python二进制可执行文件无法在OS x上执行:importerror没有名为PyQt4的模块

时间:2016-08-12 15:45:42

标签: python macos pyqt4 pyinstaller

我使用pyinstaller和以下命令在Mac上为python脚本创建了一个二进制可执行文件:

  

pyinstaller --onefile --windowed chatEdit.py

也尝试了这个:

  

pyinstaller --windowed chatEdit.py

在每种情况下,可执行文件都无法运行。

终端屏幕打开并显示以下消息:

Failed to execute script chatEdit
Traceback (most recent call last):
  File "chatEdit.py", line 3, in <module>
ImportError: No module named PyQt4
logout

请帮忙!

我的.spec文件:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['chatEdit.py'],
             pathex=['/Users/Shubhi/Documents/vin'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='chatEdit',
          debug=False,
          strip=False,
          upx=True,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='chatEdit')
app = BUNDLE(coll,
             name='chatEdit.app',
             icon=None,
             bundle_identifier=None)

1 个答案:

答案 0 :(得分:0)

您似乎错过了.spec文件中的PyQt

我希望我的app.spec会帮助你。注意 hiddenimports中'PyQt4.QtCore','PyQt4.QtGui'

# -*- mode: python -*-
a = Analysis(['app.py'],
             pathex=['d:\\4com\\consultant\\consultant'],
             hiddenimports=['grab.transport.curl', 'pycurl', 'weblib.user_agent', 'grab.response','openpyxl',
             'openpyxl.styles', 'cookielib','_LWPCookieJar','_MozillaCookieJar','PyQt4.QtCore', 'PyQt4.QtGui',
             'gui'],
             hookspath=None,
             runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='documents.exe',
          debug=False,
          strip=None,
          upx=True,
          console=True )