在Windows 7上打包PyQt4应用时出现错误
我正在尝试在Windows上打包一个PyQt4应用程序。我试过使用cx_freeze和py2exe这两个工具。但是,当我用cx_freeze生成可执行文件后,运行时出现了以下错误:
ImportError: No module named image
尽管我已经安装了PIL,但还是出现了这个问题。
当我使用py2exe时,我遇到了以下错误:
ImportError: No module named PyQt4
这是我为cx_freeze准备的设置文件:
from cx_Freeze import setup, Executable
includes = ["sip","requests","PyQt4","PIL"]
exe = Executable(
script="trial.py",
base="Win32GUI"
)
setup(
options = {"build_exe": {"includes":includes}},
executables = [exe],
data_files = [
('phonon_backend', [
'C:\Python27\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll'
]),
('imageplugins', [
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll',
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qjpeg4.dll',
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qsvg4.dll',
]),
]
)
这是我为py2exe准备的设置文件:
from distutils.core import setup
import py2exe
setup(windows=['trial.py'],
options={
'py2exe': {
"dll_excludes": [
"MSVCP90.dll",
"MSWSOCK.dll",
"mswsock.dll",
"powrprof.dll",
],
'includes': [
'sip',
'PyQt4',
],
}
},
data_files = [
('phonon_backend', [
'C:\Python27\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll'
]),
('imageplugins', [
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll',
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qjpeg4.dll',
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qsvg4.dll',
]),
],
)
这是我在脚本中导入的内容:
from PyQt4 import QtCore, uic
from PyQt4 import QtGui
我该如何解决这些错误呢?谢谢。
2 个回答
0
试试这个
from distutils.core import setup
import py2exe
setup(windows=['trial.py'],
options={
'py2exe': {
"dll_excludes": [
"MSVCP90.dll",
"MSWSOCK.dll",
"mswsock.dll",
"powrprof.dll",
],
'includes': [
'sip',
'PyQt4.QtCore',
'PyQt4.QtGui',
],
}
},
data_files = [
('phonon_backend', [
'C:\Python27\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll'
]),
('imageplugins', [
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll',
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qjpeg4.dll',
'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qsvg4.dll',
]),
],
)
1
虽然这不是你想要的答案,但老实说,我建议你尽量使用PyInstaller。我发现它比py2exe和cx_Freeze好用得多,而且它还在不断更新维护,并且自动支持PyQt4。