我想使用py2exe-0.6.9.win32使用下列對象庫與相關下載文件名包,我已經寫在Python2.6.5的應用程序:py2exe和numpy的不相處
matplotlib -0.99.3.win32
SciPy的-0.8.0b1-的win32
wxPython2.8-Win32的Unicode的2.8.11.0
我在嘗試啓動生成的.exe文件時收到錯誤消息。此刻,錯誤消息與numpy有關,儘管在此之前我正在獲取與matplot lib數據文件不相關的內容,因此阻止了我的exe文件的啓動。
而不是發佈一英里的代碼和所有的錯誤消息,我發佈了一個更一般的問題:任何人都可以看到一些指示,使所有這些對象庫和版本一起使用py2exe創建工作exe文件?
我一直在閱讀有關該主題的谷歌搜索的東西,但它似乎像一個瘋狂的追逐,因爲每個人都在使用不同版本的不同的東西。如果這些對象庫有些不同,我可以改變這些對象庫的某些版本,但是我已經在這個信號處理應用程序中編寫了5,000行代碼,並且我不希望重新編寫所有這些對象,如果可能。
編輯:
這裏是我的代碼在一個名爲GUIdiagnostics.py文件簡化版本,我做了測試我的py2exe腳本導入我需要的所有庫的能力我的實際應用:
import time
import wxversion
import wx
import csv
import os
import pylab as p
from scipy import stats
import math
from matplotlib import *
from numpy import *
from pylab import *
import scipy.signal as signal
import scipy.optimize
import Tkinter
ID_EXIT = 130
class MainWindow(wx.Frame):
def __init__(self, parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title, size = (500,500), style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
# A button
self.button =wx.Button(self, label="Click Here", pos=(160, 120))
self.Bind(wx.EVT_BUTTON,self.OnClick,self.button)
# the combobox Control
self.sampleList = ['first','second','third']
self.lblhear = wx.StaticText(self, label="Choose TestID to filter:", pos=(20, 75))
self.edithear = wx.ComboBox(self, pos=(160, 75), size=(95, -1), choices=self.sampleList, style=wx.CB_DROPDOWN)
# the progress bar
self.progressMax = 3
self.count = 0
self.newStep='step '+str(self.count)
self.dialog = None
#-------Setting up the menu.
# create a new instance of the wx.Menu() object
filemenu = wx.Menu()
# enables user to exit the program gracefully
filemenu.Append(ID_EXIT, "E&xit", "Terminate the program")
#------- Creating the menu.
# create a new instance of the wx.MenuBar() object
menubar = wx.MenuBar()
# add our filemenu as the first thing on this menu bar
menubar.Append(filemenu,"&File")
# set the menubar we just created as the MenuBar for this frame
self.SetMenuBar(menubar)
#----- Setting menu event handler
wx.EVT_MENU(self,ID_EXIT,self.OnExit)
self.Show(True)
def OnExit(self,event):
self.Close(True)
def OnClick(self,event):
try:
if not self.dialog:
self.dialog = wx.ProgressDialog("Progress in processing your data.", self.newStep,
self.progressMax,
style=wx.PD_CAN_ABORT
| wx.PD_APP_MODAL
| wx.PD_SMOOTH)
self.count += 1
self.newStep='Start'
(keepGoing, skip) = self.dialog.Update(self.count,self.newStep)
TestID = self.edithear.GetValue()
self.count += 1
self.newStep='Continue.'
(keepGoing, skip) = self.dialog.Update(self.count,self.newStep)
myObject=myClass(TestID)
print myObject.description
self.count += 1
self.newStep='Finished.'
(keepGoing, skip) = self.dialog.Update(self.count,self.newStep)
self.count = 0
self.dialog.Destroy()
except:
self.dialog.Destroy()
import sys, traceback
xc = traceback.format_exception(*sys.exc_info())
d = wx.MessageDialog(self, ''.join(xc),"Error",wx.OK)
d.ShowModal() # Show it
d.Destroy() #finally destroy it when finished
class myClass():
def __init__(self,TestID):
self.description = 'The variable name is: '+str(TestID)+'. '
app = wx.PySimpleApp()
frame = MainWindow(None,-1,"My GUI")
app.MainLoop()
下面是setup.py的代碼,這是一個包含我的py2exe代碼的文件:
from distutils.core import setup
import py2exe
# Remove the build folder, a bit slower but ensures that build contains the latest
import shutil
shutil.rmtree("build", ignore_errors=True)
# my setup.py is based on one generated with gui2exe, so data_files is done a bit differently
data_files = []
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', 'sqlite3'
]
packages = ['pytz']
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll']
icon_resources = []
bitmap_resources = []
other_resources = []
# add the mpl mpl-data folder and rc file
import matplotlib as mpl
data_files += mpl.get_py2exe_datafiles()
setup(
windows=['GUIdiagnostics.py'],
# compressed and optimize reduce the size
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
# using 2 to reduce number of files in dist folder
# using 1 is not recommended as it often does not work
"bundle_files": 2,
"dist_dir": 'dist',
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
# using zipfile to reduce number of files in dist
zipfile = r'lib\library.zip',
data_files=data_files
)
我通過鍵入以下行窗口的命令行界面(CMD.EXE)運行這段代碼按以下鏈接:
setup.py py2exe
Py2exe然後運行,但是當我嘗試推出所產生的exe文件,它會創建一個包含以下消息的日誌文件:
Traceback (most recent call last):
File "setup.py", line 6, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "pylab.pyo", line 1, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\pylab.pyo", line 206, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\mpl.pyo", line 3, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\axes.pyo", line 14, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\collections.pyo", line 21, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\backend_bases.pyo", line 32, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\widgets.pyo", line 12, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\mlab.pyo", line 388, in <module>
TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'
誰能告訴我如何編輯setup.py使py2exe可以創建一個可用的可執行文件運行numpy的,SciPy的,matplotlib等?
第二個編輯:
確定。今天我再次嘗試了RC的建議,現在我對此有了一個新的想法,並且我得到了同樣的錯誤,但是我將它包括在下面。以下是我在以下模板中創建的名爲cxsetup.py的文件的代碼:http://cx-freeze.sourceforge.net/cx_Freeze.html。
python cxsetup.py build
產生在命令行以下錯誤::
ImportError: No module named cx_Freeze
在目錄
from cx_Freeze import setup, Executable
setup(
name = "Potark",
version = "0.1",
description = "My application.",
executables = [Executable("Potark-ICG.py")])
不幸的是,在命令行(cmd.exe的)與該命令運行它命令行是我的應用程序的目錄,位於桌面的子文件夾中。這與python應用程序的目錄不同,但我認爲cmd.exe可以解決這個問題,因爲python可以解決這個問題。 我錯了嗎?作爲測試,我添加下面的代碼行cxsetup.py的第一行:
import matplotlib
但是,所產生的幾乎是相同的錯誤:
ImportError: No module named matplotlib
我試圖保持該線程重點突出,但時間長了。 任何人都可以幫助我嗎?我不想做的切換所有工作只cx_freeze發現它不能與numpy的,matplotlib,SciPy的,等工作
也許你可以嘗試與cxfreeze,看看它是否有助於創建一個工作的exe – 2011-02-04 07:37:38