我有一个名为UIMaster.py的python程序,我使用py2exe转换为可执行文件。当我在终端中运行setup.py文件时,它正在创建build和dist文件夹,并且在dist文件夹中包含一个UIMaster.exe文件;当我双击它时,终端窗口弹出,然后等待一秒钟并写入一些文本(关闭太快,无法阅读)然后关闭。但是,当我用python运行我的python程序时,一切正常。我不是百分百确定为什么会这样。我正在使用matplotlib,我认为这可能导致问题。我确信我需要从选项中排除一些内容并可能添加一些数据文件,但我不确定这是否正确。当我进入终端并cd dist然后运行UIMaster.exe时,我收到以下消息:
/*
* Since there was no protocol part specified, we guess what protocol it
* is based on the first letters of the server name.
*/
/* Note: if you add a new protocol, please update the list in
* lib/version.c too! */
if(checkprefix("FTP.", conn->host.name))
protop = "ftp";
else if(checkprefix("DICT.", conn->host.name))
protop = "DICT";
else if(checkprefix("LDAP.", conn->host.name))
protop = "LDAP";
else if(checkprefix("IMAP.", conn->host.name))
protop = "IMAP";
else if(checkprefix("SMTP.", conn->host.name))
protop = "smtp";
else if(checkprefix("POP3.", conn->host.name))
protop = "pop3";
else {
protop = "http";
}
以下是我的setup.py中的代码:
Traceback (most recent call last):
File "UIMaster.py", line 7, in <module>
File "matplotlib\__init__.pyc", line 1100, in <module>
File "matplotlib\__init__.pyc", line 947, in rc_params
File "matplotlib\__init__.pyc", line 789, in matplotlib_fname
File "matplotlib\__init__.pyc", line 325, in wrapper
File "matplotlib\__init__.pyc", line 693, in _get_data_path_cached
File "matplotlib\__init__.pyc", line 689, in _get_data_path
RuntimeError: Could not find the matplotlib data files
我也尝试过以下操作,但仍然会收到相同的错误消息:
from distutils.core import setup
import zmq.libzmq
import py2exe
import numpy
setup(
console = ['UIMaster.py'],
zipfile='lib/library.zip',
options={
'py2exe': {
'includes': ['zmq.backend.cython'],
'excludes': ['zmq.libzmq'],
'dll_excludes': ['libzmq.pyd'],
}
},
data_files=[
('lib', (zmq.libzmq.__file__,))
]
)
最后,我尝试了以下操作并得到了相同的错误消息:
from distutils.core import setup
import zmq.libzmq
import py2exe
import numpy
import matplotlib
import pylab
setup(
console = ['UIMaster.py'],
zipfile='lib/library.zip',
options={
'py2exe': {
'includes': ['zmq.backend.cython'],
'excludes': ['zmq.libzmq','_gtkagg', '_tkagg'],
'dll_excludes': ['libzmq.pyd'],
}
},
data_files=[
('lib', (zmq.libzmq.__file__,),matplotlib.get_py2exe_datafiles() )
]
)
注意:我还需要调整zmq模块
我想在pyinstaller上使用py2exe只是因为我不熟悉pyinstaller但是如果有人可以给我一些关于pyinstaller的指针,那么我就可以将它用于我的可执行转换。
编辑:我试图使用pyinstaller而且我一直在
from distutils.core import setup
import zmq.libzmq
import py2exe
import matplotlib
setup(
console = ['UIMaster.py'],
zipfile='lib/library.zip',
options={
'py2exe': {
'packages': ['matplotlib', 'pytz'],
'includes': ['zmq.backend.cython'],
'excludes': ['zmq.libzmq','_gtkagg', '_tkagg'],
'dll_excludes': ['libzmq.pyd','libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll',
'libgtk-win32-2.0-0.dll',
'libglib-2.0-0.dll',
'libcairo-2.dll',
'libpango-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libglade-2.0-0.dll',
'libgmodule-2.0-0.dll',
'libgthread-2.0-0.dll',
'QtGui4.dll', 'QtCore.dll',
'QtCore4.dll'],
}
},
data_files=[
('lib', (zmq.libzmq.__file__,),matplotlib.get_py2exe_datafiles(),)
]
)
我还需要做些什么来启动并运行可执行文件吗?我已经生成了build和dist文件夹,但不知道为什么程序不会从可执行文件中弹出。多谢你们!
编辑:使用matplotlib.get_py2exe_datafiles()时
当我转到dist文件夹并运行.exe时,会产生以下错误:
IOError Errno[22] invalid mode <'rb'> or filename: "