Python 尝试在Windows 7上打包PyQt4应用程序时出错

Python 尝试在Windows 7上打包PyQt4应用程序时出错,python,pyqt,pyqt4,py2exe,cx-freeze,Python,Pyqt,Pyqt4,Py2exe,Cx Freeze,我正在尝试在Windows上打包PyQt4应用程序。我尝试过使用cx\u freeze和py2exe。但是,在使用cx_freeze时,我在尝试运行生成的可执行文件时出现以下错误: ImportError: No module named image 尽管安装了PIL,但仍会发生这种情况 当我使用py2exe时,会出现以下错误: ImportError: No module named PyQt4 以下是cx\U冻结的设置文件: from cx_Freeze import setup, Ex

我正在尝试在Windows上打包PyQt4应用程序。我尝试过使用cx\u freeze和py2exe。但是,在使用cx_freeze时,我在尝试运行生成的可执行文件时出现以下错误:

ImportError: No module named image
尽管安装了PIL,但仍会发生这种情况

当我使用py2exe时,会出现以下错误:

ImportError: No module named PyQt4
以下是cx\U冻结的设置文件:

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
我怎样才能消除这些错误呢?谢谢。

试试这个

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',
        ]),
],

)

虽然不是你想要的答案,但老实说,如果可能的话,我建议你使用。我发现它比py2exe和cx_Freeze工作得好得多,它得到了积极的维护,并且包括对PyQt4的自动支持

作为附议,PyInstaller是我阅读问题时的第一个想法。我使用它来打包用c++/python编写的计算包,使用PyQt4(以及matplotlib和numpy等,其中内置了特定的钩子)for frontend(),效果很好。将
Image
添加到setup.py文件中的includes如何?