PyInstaller包括特定模块后仍然出现缺少模块错误

4

我的应用在Windows上使用Pyinstaller编译成了.exe文件,但是在Mac上我无法构建出可用的.app文件。我已经尝试了--onefile和--onedir,但是没有成功,该应用程序只会打开一下然后立即关闭并报告崩溃。看起来像是模块导入的问题,但是我已经通过路径pathex和datas中的.spec文件导入了我知道如何导入的所有模块。我已经重新安装了pyinstaller的发布版和开发版。还有什么其他的想法吗?谢谢!

系统信息: PyInstaller: 3.3.1 Python: 3.6.3 平台: Darwin-16.7.0-x86_64-i386-64bit

命令行: pyinstaller --onedir --name=StaticBot --windowed StaticBot.spec

spec文件:

# -*- mode: python -*-

import sys
sys.setrecursionlimit(5000)

block_cipher = None


a = Analysis(['../main.py'],
             pathex=[
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5',
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/psutil', 
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/grid_objs',
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/offline',
                 '/Users/justint/Documents/Justin/Dev/Staticbot'
             ],
             binaries=[],
             datas=[ ('../res_rc.py', '.'), 
                ('../ui.py', '.'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/plotly/', './plotly/plotly/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/grid_objs/', './plotly/grid_objs/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/offline/', './plotly/offline/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/package_data/default-schema.json', './plotly/package_data/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/package_data/graphWidget.js', './plotly/package_data/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/package_data/plotly.min.js', './plotly/package_data/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/psutil', './psutil')
                ],
             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,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='Staticbot',
          debug=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          icon='/Users/justint/Documents/Justin/Dev/Staticbot/_output_mac/Staticbot.icns',
          console=False )
app = BUNDLE(exe,
             name='Staticbot.app',
             icon='/Users/justint/Documents/Justin/Dev/Staticbot/_output_mac/Staticbot.icns',
             bundle_identifier=None)

警告列表:

missing module named pyimod03_importers - imported by /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py
missing module named 'pkg_resources.extern.pyparsing' - imported by pkg_resources._vendor.packaging.requirements, pkg_resources._vendor.packaging.markers
missing module named netbios - imported by uuid
missing module named win32wnet - imported by uuid
missing module named __builtin__ - imported by numpy.core.numerictypes, numpy.core.numeric, numpy.distutils.misc_util, numpy.lib.function_base, numpy.lib._iotools, numpy.ma.core, numpy, pkg_resources._vendor.pyparsing
missing module named ordereddict - imported by pkg_resources._vendor.pyparsing
missing module named 'com.sun' - imported by pkg_resources._vendor.appdirs
missing module named com - imported by pkg_resources._vendor.appdirs
missing module named win32api - imported by distutils.msvccompiler, pkg_resources._vendor.appdirs
missing module named 'win32com.shell' - imported by pkg_resources._vendor.appdirs
missing module named StringIO - imported by six, urllib3.packages.six, requests.compat, numpy.lib.utils, numpy.testing.nose_tools.utils, numpy.lib.format, pkg_resources._vendor.six
missing module named __main__ - imported by pkg_resources
missing module named multiprocessing.SimpleQueue - imported by multiprocessing, concurrent.futures.process
missing module named multiprocessing.set_start_method - imported by multiprocessing, multiprocessing.spawn
missing module named multiprocessing.get_start_method - imported by multiprocessing, multiprocessing.spawn
missing module named multiprocessing.TimeoutError - imported by multiprocessing, multiprocessing.pool
missing module named multiprocessing.get_context - imported by multiprocessing, multiprocessing.pool, multiprocessing.managers, multiprocessing.sharedctypes
missing module named multiprocessing.BufferTooShort - imported by multiprocessing, multiprocessing.connection
missing module named multiprocessing.AuthenticationError - imported by multiprocessing, multiprocessing.connection
missing module named pkg_resources.extern.packaging - imported by pkg_resources.extern, pkg_resources, setuptools.dist, setuptools.command.egg_info
missing module named pkg_resources.extern.appdirs - imported by pkg_resources.extern, pkg_resources
missing module named 'pkg_resources.extern.six.moves' - imported by pkg_resources, pkg_resources._vendor.packaging.requirements
missing module named pkg_resources.extern.six - imported by pkg_resources.extern, pkg_resources
missing module named 'multiprocessing.forking' - imported by /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/loader/rthooks/pyi_rth_multiprocessing.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named _winreg - imported by platform, requests.utils, numpy.distutils.cpuinfo, /Users/justint/Documents/Justin/Dev/Staticbot/main.py, pkg_resources._vendor.appdirs
missing module named java - imported by platform, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named 'java.lang' - imported by platform, /Users/justint/Documents/Justin/Dev/Staticbot/main.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named msvcrt - imported by subprocess, getpass, multiprocessing.spawn, multiprocessing.popen_spawn_win32, numpy.distutils.mingw32ccompiler, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named _winapi - imported by subprocess, multiprocessing.reduction, multiprocessing.connection, multiprocessing.heap, multiprocessing.popen_spawn_win32, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named winreg - imported by platform, mimetypes, urllib.request, requests.utils, distutils.msvccompiler, distutils.msvc9compiler, distutils._msvccompiler, numpy.distutils.cpuinfo, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named urllib.splittag - imported by urllib, setuptools.py26compat
missing module named urllib.getproxies_environment - imported by urllib, requests.compat
missing module named urllib.proxy_bypass_environment - imported by urllib, requests.compat
missing module named urllib.proxy_bypass - imported by urllib, requests.compat
missing module named urllib.getproxies - imported by urllib, requests.compat
missing module named urllib.urlencode - imported by urllib, requests.compat
missing module named urllib.unquote_plus - imported by urllib, requests.compat
missing module named urllib.quote_plus - imported by urllib, requests.compat
missing module named urllib.unquote - imported by urllib, requests.compat
missing module named urllib.quote - imported by urllib, requests.compat
missing module named _dummy_threading - imported by dummy_threading, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named nt - imported by os, ntpath, shutil, pathlib, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named 'org.python' - imported by copy, setuptools.sandbox, /Users/justint/Documents/Justin/Dev/Staticbot/main.py, xml.sax
missing module named org - imported by pickle, /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named Queue - imported by urllib3.connectionpool
missing module named "'urllib3.packages.six.moves.urllib'.parse" - imported by urllib3.request, urllib3.poolmanager
runtime module named urllib3.packages.six.moves - imported by http.client, urllib3.connectionpool, urllib3.util.response, 'urllib3.packages.six.moves.urllib', urllib3.response
missing module named backports - imported by urllib3.packages.ssl_match_hostname
missing module named socks - imported by urllib3.contrib.socks
missing module named 'OpenSSL.crypto' - imported by urllib3.contrib.pyopenssl
missing module named 'cryptography.x509' - imported by urllib3.contrib.pyopenssl
missing module named 'cryptography.hazmat' - imported by urllib3.contrib.pyopenssl
missing module named cryptography - imported by urllib3.contrib.pyopenssl
missing module named OpenSSL - imported by urllib3.contrib.pyopenssl
missing module named _abcoll - imported by urllib3.packages.ordered_dict
missing module named dummy_thread - imported by urllib3.packages.ordered_dict, numpy.core.arrayprint
missing module named thread - imported by urllib3.packages.ordered_dict, numpy.core.arrayprint
missing module named Cookie - imported by requests.compat
missing module named cookielib - imported by requests.compat
missing module named urllib2 - imported by requests.compat, setuptools.package_index, numpy.lib._datasource
missing module named urlparse - imported by requests.compat, numpy.lib._datasource
missing module named simplejson - imported by requests.compat
missing module named IPython - imported by plotly.plotly.plotly
runtime module named six.moves - imported by plotly.plotly.plotly, plotly.plotly.chunked_requests.chunked_request, 'six.moves.urllib'
missing module named "'six.moves.urllib'.parse" - imported by plotly.plotly.chunked_requests.chunked_request
missing module named pandas - imported by plotly.graph_objs.graph_objs, plotly.figure_factory._county_choropleth
missing module named numpy.lib.i0 - imported by numpy.lib, numpy.dual
missing module named numpy.linalg.inv - imported by numpy.linalg, numpy.matrixlib.defmatrix, numpy.lib.polynomial
missing module named cPickle - imported by numpy.core.numeric, numpy.lib.format, numpy.lib.npyio, numpy.ma.core
missing module named cStringIO - imported by cPickle
missing module named copy_reg - imported by cPickle, cStringIO, numpy.core
missing module named ConfigParser - imported by numpy.distutils.system_info, numpy.distutils.npy_pkg_config
missing module named 'numpy_distutils.cpuinfo' - imported by numpy.f2py.diagnose
missing module named 'numpy_distutils.fcompiler' - imported by numpy.f2py.diagnose
missing module named 'numpy_distutils.command' - imported by numpy.f2py.diagnose
missing module named numpy_distutils - imported by numpy.f2py.diagnose
missing module named numpy.testing.memusage - imported by numpy.testing, numpy.f2py.f2py_testing
missing module named numpy.testing.jiffies - imported by numpy.testing, numpy.f2py.f2py_testing
missing module named setuptools_svn - imported by setuptools.command.egg_info
missing module named 'setuptools.extern.six' - imported by setuptools, setuptools.extension
missing module named wincertstore - imported by setuptools.ssl_support
missing module named 'backports.ssl_match_hostname' - imported by setuptools.ssl_support
missing module named win32com - imported by setuptools.sandbox
missing module named 'pkg_resources.extern.packaging.version' - imported by setuptools.msvc
missing module named 'setuptools.extern.six.moves' - imported by setuptools.dist, setuptools.command.easy_install, setuptools.sandbox, setuptools.command.setopt, setuptools.package_index, setuptools.ssl_support, setuptools.command.egg_info, setuptools.command.py36compat, setuptools.msvc
missing module named setuptools.extern.six - imported by setuptools.extern, setuptools.monkey, setuptools.dist, setuptools.depends, setuptools.command.easy_install, setuptools.sandbox, setuptools.package_index, setuptools.command.bdist_egg, setuptools.command.egg_info, setuptools.command.sdist, setuptools.unicode_utils, setuptools.glob, setuptools.command.develop
missing module named _findvs - imported by distutils._msvccompiler
missing module named __svn_version__ - imported by numpy.f2py.__version__
missing module named numarray - imported by numpy.distutils.system_info
missing module named Numeric - imported by numpy.distutils.system_info
missing module named commands - imported by numpy.distutils.cpuinfo
missing module named 'nose.plugins' - imported by numpy.testing.nose_tools.noseclasses, numpy.testing.nose_tools.nosetester
missing module named scipy - imported by numpy.testing.nose_tools.nosetester
missing module named 'nose.util' - imported by numpy.testing.nose_tools.noseclasses
missing module named nose - imported by numpy.testing.nose_tools.utils, numpy.testing.nose_tools.decorators, numpy.testing.nose_tools.noseclasses
missing module named numpy.core.number - imported by numpy.core, numpy.testing.nose_tools.utils
missing module named numpy.lib.imag - imported by numpy.lib, numpy.testing.nose_tools.utils
missing module named numpy.lib.real - imported by numpy.lib, numpy.testing.nose_tools.utils
missing module named numpy.lib.iscomplexobj - imported by numpy.lib, numpy.testing.nose_tools.utils
missing module named numpy.core.signbit - imported by numpy.core, numpy.testing.nose_tools.utils
missing module named win32pdh - imported by numpy.testing.nose_tools.utils
missing module named numpy.core.float64 - imported by numpy.core, numpy.testing.nose_tools.utils
missing module named numpy.core.float32 - imported by numpy.core, numpy.testing.nose_tools.utils
missing module named win32con - imported by distutils.msvccompiler
missing module named numpy.core.integer - imported by numpy.core, numpy.fft.helper
missing module named numpy.core.sqrt - imported by numpy.core, numpy.linalg.linalg, numpy.fft.fftpack
missing module named numpy.core.conjugate - imported by numpy.core, numpy.fft.fftpack
missing module named numpy.lib.triu - imported by numpy.lib, numpy.linalg.linalg
missing module named numpy.core.divide - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.object_ - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.intp - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.longdouble - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.geterrobj - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.maximum - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.add - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.complexfloating - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.inexact - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.cdouble - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.csingle - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.double - imported by numpy.core, numpy.linalg.linalg
missing module named numpy.core.single - imported by numpy.core, numpy.linalg.linalg
missing module named future_builtins - imported by numpy.lib.npyio
missing module named numpy.recarray - imported by numpy, numpy.ma.mrecords
missing module named numpy.dtype - imported by numpy, numpy.ma.mrecords, numpy.ctypeslib
missing module named numpy.expand_dims - imported by numpy, numpy.ma.core
missing module named numpy.array - imported by numpy, numpy.ma.core, numpy.ma.extras, numpy.ma.mrecords, numpy.ctypeslib
missing module named numpy.bool_ - imported by numpy, numpy.ma.core, numpy.ma.mrecords
missing module named numpy.iscomplexobj - imported by numpy, numpy.ma.core
missing module named numpy.amin - imported by numpy, numpy.ma.core
missing module named numpy.amax - imported by numpy, numpy.ma.core
missing module named numpy.ndarray - imported by numpy, numpy.ma.core, numpy.ma.extras, numpy.ma.mrecords, numpy.ctypeslib
missing module named numpy.histogramdd - imported by numpy, numpy.lib.twodim_base
missing module named numpy.eye - imported by numpy, numpy.core.numeric
missing module named sets - imported by pytz.tzinfo
missing module named UserDict - imported by pytz.lazy
missing module named psutil._psutil_aix - imported by psutil, psutil._psaix
missing module named psutil._psutil_sunos - imported by psutil, psutil._pssunos
missing module named psutil._psutil_bsd - imported by psutil, psutil._psbsd
missing module named psutil._psutil_windows - imported by psutil, psutil._pswindows
missing module named _psutil_linux - imported by psutil
missing module named win32process - imported by /Users/justint/Documents/Justin/Dev/Staticbot/main.py
missing module named win32gui - imported by /Users/justint/Documents/Justin/Dev/Staticbot/main.py

这是对我有效的所有解决方案,但我希望它能更普遍化。 - bart cubrich
3个回答

2

问题已经解决。看起来解决方案是使用--onedir而不是--onefile,并切换回最新版本的PyInstaller而不是dev pyqt5-fix版本,将org.qt-project.Qt.QtWebEngineCore设置为bundle_identifier。此外,请确保除了PyQt5之外还安装了Qt5。

命令

pyinstaller --onefile --name=Staticbot --windowed Staticbot.spec

要求

系统

  • Python 3.6.5
  • Qt 5.10.1

Python

  • PyQt5 5.10.1
  • PyInstaller 3.3.1
  • 规格文件

规格文件

block_cipher = None

a = Analysis(['../main.py'],
            pathex=[
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/psutil', 
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/grid_objs',
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/offline',
                 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5',
                 '/Users/justint/Documents/Justin/Dev/Staticbot'
             ],
              binaries=[],
              datas=[('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/plotly/', './plotly/plotly/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/grid_objs/', './plotly/grid_objs/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/offline/', './plotly/offline/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/package_data/default-schema.json', './plotly/package_data/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/package_data/graphWidget.js', './plotly/package_data/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plotly/package_data/plotly.min.js', './plotly/package_data/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/QtWebEngine.so', './PyQt5/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/QtWebEngineCore.so', './PyQt5/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/QtWebEngineWidgets.so', './PyQt5/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtWebEngineCore.framework/Helpers/QtWebEngineProcess.app', './PyQt5/Qt/lib/QtWebEngineCore.framework/Helpers/'),
                ('/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/psutil', './psutil')
                ],
              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='Staticbot',
            debug=False,
            strip=False,
            upx=False,
            console=False )


coll = COLLECT( exe,
                a.binaries,
                a.scripts,
                a.zipfiles,
                a.datas,
                strip=False,
                upx=False,
                name='Staticbot')

app = BUNDLE(coll,
             name='Staticbot.app',
             bundle_identifier='org.qt-project.Qt.QtWebEngineCore')

2

在使用虚拟环境时,请确保运行正确的PyInstaller。您需要使用安装在特定虚拟环境中的PyInstaller。


这对我来说就是这样了,即使全局安装的版本号相同,也无法工作。您必须使用与文件所使用的 venv 相同的版本。 - Hakaishin

1

很难确定为什么.app无法运行,但可能是由于缺少模块,正如您所建议的那样。通过从终端运行.app(而不是双击可执行文件),您可以更轻松地查看与应用程序过早关闭相关的错误消息:

/path/to/app/dist/MyApp.app/Contents/MacOS/MyApp

如果此处报告了无法调试的错误,请将其作为编辑添加到您的问题中。
如果程序因未能导入模块而失败,则可以将该模块添加到.spec文件的hiddenimports列表中,然后再次运行PyInstaller(pyinstaller myfile.spec)。或者,您可以在PyInstaller命令中添加以下选项:
pyinstaller [options] --hiddenimport=missing_module myfile.py

我认为通过pathex或datas列表导入模块并不是显式添加它们的推荐方式。


1
谢谢,我离成功又近了一步,但是在终端中运行时出现了这个错误:无法找到QtWebEngineProcess。尝试了包含QtWebEngineWidgets.so、QtWebEngineCore.so和QtWebEngine.so等文件,但还没有成功。我会继续尝试其他方法... - code4days
1
如果您还没有看到,这个帖子可能会有用:https://github.com/pyinstaller/pyinstaller/issues/3308 - apogalacticon
这似乎已经解决了很多人的问题,但出于某种原因,即使在运行pyinstaller-pyqt5_fix版本的pyinstaller时,我仍然会收到“无法找到QtWebEngineProcess Abort trap: 6”的错误。尝试将其添加到missing_modules、pathex和datas中,但迄今为止没有任何作用。 - code4days

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接