在Windows 7下打包pylab时,PySide和PyQt会发生冲突

时间:2013-12-17 10:04:25

标签: python matplotlib pyqt4 pyside pyinstaller

我尝试打包一个小脚本,用pylab做一些绘图。我在Linux下使用pyinstaller没有问题,但在Windows 7下我收到错误。在另一台安装了PySide而不安装PyQt的计算机上,包装工作正常。因此,通过删除PyQt我可以让它在我的其他计算机上工作。但是,我想知道是否有另一种解决这个问题的方法,因为我有一些使用PyQt的脚本和一些使用PySide的脚本。我使用cx_freeze得到了类似的错误。

感谢您的帮助, 丹尼尔

显示问题的示例代码:

from pylab import *
labels = 'Cakes', 'Cookies', 'Biscuits', 'Tarts'
fracs = [27, 33, 14, 19]
pie(fracs, labels=labels, autopct='%1.1f%%', startangle=90)
show()

执行打包程序时出错:

WARNING: file already exists but should not: C:\Users\..\Temp\_MEI61562\Include\pyconfig.h
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Workspace\ZLC_python\build\test\out00-PYZ.pyz\pylab", line 1, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Workspace\ZLC_python\build\test\out00-PYZ.pyz\matplotlib.pylab", line 269, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Workspace\ZLC_python\build\test\out00-PYZ.pyz\matplotlib.pyplot", line 93, in <module>
  File "C:\Workspace\ZLC_python\build\test\out00-PYZ.pyz\matplotlib.pyplot", line 80, in _backend_selection
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 409, in load_module
    module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
ImportError: DLL load failed: The specified procedure could not be found.

按照Pyinstaller --onefile warning pyconfig.h when importing scipy or scipy.signal的建议,我摆脱了警告,但错误仍然存​​在。

版本:

  • Python 2.7.5
  • PySide 1.2.1
  • PyQt 4.9.6-3
  • matplotlib 1.2.1
  • numpy 1.7.1
  • pyinstaller 2.1

1 个答案:

答案 0 :(得分:2)

我仔细查看了pyinstaller文档,找到了pyinstaller的解决方案。我在spec文件的Analysis块中使用了excludes选项:

# -*- mode: python -*-
a = Analysis(['test.py'],
         pathex=['C:\\Workspace\\ZLC_python'],
         hiddenimports=[],
         hookspath=None,
         excludes=['PyQt4'],
         runtime_hooks=None)
for d in a.datas:
    if 'pyconfig' in d[0]: 
        a.datas.remove(d)
        break
pyz = PYZ(a.pure)
exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      name='test.exe',
      debug=False,
      strip=None,
      upx=True,
      console=True )