2013-10-29 41 views
2

我有一個wxpython應用程序,當我將matplotlib作爲導入包含時,它不會構建到exe中。例如,我在我的主PY文件導入的樣子:wxpython exe沒有用pyinstaller構建

import os 
import matplotlib 
matplotlib.use('WX') 
import wx 
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas 
from matplotlib.backends.backend_wx import NavigationToolbar2Wx 
from mpl_toolkits.basemap import Basemap 
from matplotlib.figure import Figure 
import matplotlib.pyplot as plt 
import datetime 
import copy 
import wx.lib.scrolledpanel as scrolled 
import wx.lib.agw.pybusyinfo as PBI 

我使用PyInstaller 1.5.1(我似乎無法獲得2.0或2.1到我的機器上安裝右)。我也使用偉大的GUI2EXE文件來幫助指導我完成所有設置。當我編譯代碼時 - 它編譯成一個可執行文件,但exe不運行。但是,如果我註釋掉所有的matplotlib導入,則exe會生成並打開,這很好(它只是不顯示任何包含的映射)。因此,我知道我的問題是在matplotlib中導入的。

有一個警告文件,當我編譯時附加。這是很長,但前幾行是這樣的:

W: no module named termios (top-level import by tty) 
W: no module named matplotlib.rcParams (top-level import by matplotlib.figure) 
W: no module named numpy.not_equal (top-level import by numpy.numarray.ufuncs) 
W: no module named setuptools.Command (top-level import by setuptools.command.setopt) 
W: no module named numpy.testing.Tester (top-level import by numpy.polynomial) 
W: no module named numpy.compat.formatargspec (top-level import by numpy.ma.core) 

一堆的研究,這似乎是一個隱藏的進口問題(雖然我可能是錯的)。我看了文檔(http://www.pyinstaller.org/export/develop/project/doc/Manual.html#listing-hidden-imports),並用hooks-matplotlib.figure.py做了例子,在那裏我嘗試了hiddenimports=['matplotlib','figure'].我仍然得到相同的錯誤。另外,我在PyInstaller目錄中看到在hooks文件夾下已經有Matplotlib。

我不明白爲什麼我不使用PyInstaller正確構建。有什麼想法嗎?

如需進一步信息,這裏是我的安裝腳本pyinstaller:

data_files = [('AccesstoJson.py', 'C:\\Users\\Jacob\\Documents\\MyFolder\\AccesstoJson.py', 
       'DATA'), ('pic2.png', 'C:\\Users\\Jacob\\Documents\\MyFolder\\pic1.png', 
       'DATA'), ('Calculate_Distance.py', 'C:\\Users\\Jacob\\Documents\\MyFolder\\Calculate_Distance.py', 
       'DATA'), ('pic2.jpg', 'C:\\Users\\Jacob\\Documents\\MyFolder\\pic2.jpg', 
       'DATA'), ('pic3.png', 'C:\\Users\\Jacob\\Documents\\MyFolder\\pic3.png', 
       'DATA'), ('Program_Data_2013.json', 'C:\\Users\\Jacob\\Documents\\MyFolder\\Program_Data_2013.json', 
       'DATA'), ('pic4.ico', 'C:\\Users\\Jacob\\Documents\\MyFolder\\pic4.ico', 
       'DATA')] 

includes = [] 
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 
      'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 
      'Tkconstants', 'Tkinter'] 
packages = [] 
dll_excludes = [] 
dll_includes = [] 

options = [('v', '', 'OPTION')] 

analysis = Analysis(['C:\\Python27\\Lib\\site-packages\\pyinstaller-1.5.1\\support\\_mountzlib.py', 
      'C:\\Python27\\Lib\\site-packages\\pyinstaller-1.5.1\\support\\useUnicode.py', 
      'C:\\Users\\Jacob\\Documents\\MyFolder\\Scheduler_25Oct2013.py'], 
        pathex=['C:\\Python27\\Lib\\site-packages\\mpl_toolkits\\*', 'C:\\Users\\Jacob\\Documents\\MyFolder'], 
        hookspath=['C:\\Python27\\Lib\\site-packages\\numpy-1.7.1-py2.7-win32.egg'], 
        excludes=excludes) 

pyz = PYZ(analysis.pure, level=9) 

executable = EXE(pyz, 
       analysis.scripts + includes + packages + options, 
       analysis.binaries - dll_excludes + dll_includes + data_files, 
       name=r"Scheduler1.exe", 
       debug=False, 
       console=False, 
       strip=False, 
       upx=False, 
       icon=r'C:\Users\Jacob\Documents\MyFolder\pic4.ico', 
       version=None) 

回答

0

我有同樣的問題。

http://www.py2exe.org/index.cgi/MatPlotLib

matplotlib需要MPL-data文件夾運行,這不能被打包成EXE文件。無論是從站點包手動複製此文件夾或做類似:

import matplotlib 
... 
setup(
    ... 
    data_files=matplotlib.get_py2exe_datafiles(), 
) 

在您的setup.py for py2exe。它會複製data_files文件夾。