我正在尝试在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
如何摆脱错误?感谢。
答案 0 :(得分:1)
虽然不是你想要的答案,但老实说,我建议你尽可能使用PyInstaller。我发现它比py2exe和cx_Freeze好得多,它是主动维护的,它包括对PyQt4的自动支持。
答案 1 :(得分: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',
]),
],
)