PyInstaller Missing Module Errors Even After Including Specifically

14,152

Solution 1

Fixed it. Looks like the solution was a combination of using --onedir instead of --onefile and switching back to the latest release of PyInstaller instead of the dev pyqt5-fix version, and setting org.qt-project.Qt.QtWebEngineCore as the bundle_identifier. Also make sure you have Qt5 installed in addition to PyQt5.

Command

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

Requirements

System

  • Python 3.6.5
  • qt 5.10.1

Python

  • PyQt5 5.10.1
  • PyInstaller 3.3.1
  • Spec File

Spec File

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

Solution 2

It's a bit difficult to determine why the .app is not running, but it may be due to a missing module, as you suggest. You can more easily see the error message associated with the premature closing of the application by running the .app from the terminal (rather than double-clicking the executable file):

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

If this reports an error that you can not debug, add it to your question as an edit.

If the program fails because it has failed to import a module, you can add the module to the hiddenimports list in the .spec file and run PyInstaller again (pyinstaller myfile.spec). Or you could add the following option to your PyInstaller command:

pyinstaller [options] --hiddenimport=missing_module myfile.py

I do not think that importing the modules through the pathex or datas lists is the recommended way to explicitly add them.

Solution 3

Make sure to run the correct pyinstaller when you're using a virtual env. You need to use the one that is installed in that specific venv.

Share:
14,152
code4days
Author by

code4days

Updated on June 09, 2022

Comments

  • code4days
    code4days almost 2 years

    Pyinstaller compiles my app into an .exe on Windows fine, but I'm not able to build a working .app on Mac. I've tried --onefile and --onedir, but no dice, the app just opens and then closes immediately reporting a crash. It looks like a module import issue, but I've tried importing all the modules I know how through the .spec file in pathex and datas. I've reinstalled pyinstaller to both release and dev versions. Any ideas what else I can try? Thanks!

    SYSTEM: PyInstaller: 3.3.1 Python: 3.6.3 Platform: Darwin-16.7.0-x86_64-i386-64bit

    COMMAND: pyinstaller --onedir --name=StaticBot --windowed StaticBot.spec

    SPEC FILE:

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

    WARNING LIST:

    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