PySide和PyQt在Windows 7下封装pylab时发生冲突。

时间:2021-08-26 05:03:00

I tried to package a small script which does some plotting with pylab. I used pyinstaller under Linux without a problem but under Windows 7 I get an error. On a different computer which has PySide but not PyQt installed the packaging worked. Thus by removing PyQt I can get it to work on my other computer. However, I would like to know if there is another way around this problem since I have some scripts which use PyQt and some which use PySide. I got a similar error by using cx_freeze.

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

Thanks for your help, Daniel

谢谢你的帮助,丹尼尔

Example code which shows the problem:

显示问题的示例代码:

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

Produced error executing the packaged program:

执行打包程序时产生错误:

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.

By following the suggestions from Pyinstaller --onefile warning pyconfig.h when importing scipy or scipy.signal I got rid of the warning but the error remains.

通过遵循Pyinstaller—一个文件警告pyconfig的建议。当导入scipy或scipy时。我去掉了警告信号,但错误仍然存在。

Versions:

版本:

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

1 个解决方案

#1


2  

I had a closer look at the pyinstaller documentation and found a solution for pyinstaller. I used the excludes option in the Analysis block of the spec file:

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

# -*- 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 )

#1


2  

I had a closer look at the pyinstaller documentation and found a solution for pyinstaller. I used the excludes option in the Analysis block of the spec file:

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

# -*- 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 )