简体   繁体   中英

Pyinstaller exe fails to execute script

I am trying to turn my project into a standalone executable so it can run on other machines without requiring Python to be installed.

I ran the following command in said file's directory:

pyinstaller --onefile -w main.py

PyInstaller seems to work correctly, but when I run the newly formed executable file, the script fails to load the application. However, when I run the file main.py , the application runs perfectly.

Here is my project, and I want to make sure that it is possible to compile before resuming progress.

Here is a screenshot of the error I am getting.

Log files on debug buld:


C:\Users\sguser\Desktop\FoodNewsApp>pyinstaller --onefile --debug=all main.py
103 INFO: PyInstaller: 3.6
103 INFO: Python: 3.8.2
105 INFO: Platform: Windows-10-10.0.18362-SP0
107 INFO: wrote C:\Users\sguser\Desktop\FoodNewsApp\main.spec
111 INFO: UPX is not available.
123 INFO: Extending PYTHONPATH with paths
['C:\\Users\\sguser\\Desktop\\FoodNewsApp',
 'C:\\Users\\sguser\\Desktop\\FoodNewsApp']
124 INFO: checking Analysis
125 INFO: Building Analysis because Analysis-00.toc is non existent
125 INFO: Initializing module dependency graph...
133 INFO: Caching module graph hooks...
154 INFO: Analyzing base_library.zip ...
3454 INFO: Processing pre-find module path hook   distutils
3456 INFO: distutils: retargeting to non-venv dir 'c:\\users\\sguser\\appdata\\local\\programs\\python\\python38-32\\lib'
6922 INFO: Caching module dependency graph...
7088 INFO: running Analysis Analysis-00.toc
7109 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\sguser\appdata\local\programs\python\python38-32\python.exe
7230 INFO: Analyzing C:\Users\sguser\Desktop\FoodNewsApp\main.py
7911 INFO: Processing pre-find module path hook   site
7913 INFO: site: retargeting to fake-dir 'c:\\users\\sguser\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\fake-modules'
9213 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
12127 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
14474 INFO: Processing pre-safe import module hook   six.moves
c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\traitlets\config\loader.py:795: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if len(key) is 1:
c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\traitlets\config\loader.py:804: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if len(key) is 1:
42337 INFO: Processing module hooks...
42337 INFO: Loading module hook "hook-babel.py"...
42464 INFO: Loading module hook "hook-certifi.py"...
42466 INFO: Loading module hook "hook-distutils.py"...
42468 INFO: Loading module hook "hook-encodings.py"...
42588 INFO: Loading module hook "hook-IPython.py"...
43072 INFO: Excluding import 'tkinter'
43077 INFO:   Removing import of tkinter from module IPython.lib.clipboard
43079 INFO: Import to be excluded not found: 'PySide'
43079 INFO: Excluding import 'PyQt4'
43085 INFO: Excluding import 'matplotlib'
43091 INFO:   Removing import of matplotlib._pylab_helpers from module IPython.core.pylabtools
43091 INFO:   Removing import of matplotlib from module IPython.core.pylabtools
43092 INFO:   Removing import of matplotlib.pyplot from module IPython.core.pylabtools
43092 INFO:   Removing import of matplotlib.backend_bases from module IPython.core.pylabtools
43093 INFO:   Removing import of matplotlib.figure from module IPython.core.pylabtools
43095 INFO: Excluding import 'PyQt5'
43104 INFO: Import to be excluded not found: 'gtk'
43105 INFO: Loading module hook "hook-jedi.py"...
43351 INFO: Loading module hook "hook-lib2to3.py"...
43359 INFO: Loading module hook "hook-lxml.etree.py"...
43363 INFO: Loading module hook "hook-matplotlib.backends.py"...
44222 INFO:   Matplotlib backend "GTK3Agg": ignored
    backend Gtk3Agg requires cairo
44703 INFO:   Matplotlib backend "GTK3Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
45159 INFO:   Matplotlib backend "MacOSX": ignored
    cannot import name '_macosx' from 'matplotlib.backends' (c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\backends\__init__.py)
c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\IPython\kernel\__init__.py:12: ShimWarning: The `IPython.kernel` package has been deprecated since IPython 4.0.You should import from ipykernel or jupyter_client instead.
  warn("The `IPython.kernel` package has been deprecated since IPython 4.0."
46192 INFO:   Matplotlib backend "nbAgg": ignored
    No module named 'ipykernel'
46691 INFO:   Matplotlib backend "Qt4Agg": ignored
    Failed to import any qt binding
47147 INFO:   Matplotlib backend "Qt4Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
47643 INFO:   Matplotlib backend "Qt5Agg": ignored
    Failed to import any qt binding
48105 INFO:   Matplotlib backend "Qt5Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
48767 INFO:   Matplotlib backend "TkAgg": added
49406 INFO:   Matplotlib backend "TkCairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
49861 INFO:   Matplotlib backend "WebAgg": ignored
    Traceback (most recent call last):
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\backends\backend_webagg.py", line 27, in <module>
    import tornado
ModuleNotFoundError: No module named 'tornado'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\backends\backend_webagg.py", line 29, in <module>
    raise RuntimeError("The WebAgg backend requires Tornado.")
RuntimeError: The WebAgg backend requires Tornado.
50465 INFO:   Matplotlib backend "WX": ignored
    No module named 'wx'
50917 INFO:   Matplotlib backend "WXAgg": ignored
    No module named 'wx'
51381 INFO:   Matplotlib backend "WXCairo": ignored
    No module named 'wx'
51872 INFO:   Matplotlib backend "agg": added
52325 INFO:   Matplotlib backend "cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
52952 INFO:   Matplotlib backend "pdf": added
53577 INFO:   Matplotlib backend "pgf": added
54038 INFO:   Matplotlib backend "ps": added
54513 INFO:   Matplotlib backend "svg": added
55119 INFO:   Matplotlib backend "template": added
55415 INFO: Loading module hook "hook-matplotlib.py"...
55822 INFO: Loading module hook "hook-numpy.core.py"...
55960 INFO: Loading module hook "hook-numpy.py"...
55962 INFO: Loading module hook "hook-openpyxl.py"...
55999 INFO: Loading module hook "hook-pandas.py"...
57080 INFO: Loading module hook "hook-PIL.Image.py"...
57482 INFO: Loading module hook "hook-PIL.py"...
57486 INFO: Excluding import 'tkinter'
57490 INFO:   Removing import of tkinter from module PIL.ImageTk
57491 INFO: Import to be excluded not found: 'PySide'
57492 INFO: Excluding import 'PyQt4'
57498 INFO: Excluding import 'PyQt5'
57502 INFO:   Removing import of PyQt5 from module PIL.ImageQt
57505 INFO: Import to be excluded not found: 'FixTk'
57505 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
57508 INFO: Excluding import 'tkinter'
57511 INFO: Import to be excluded not found: 'FixTk'
57512 INFO: Loading module hook "hook-pkg_resources.py"...
57963 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
58051 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
58374 INFO: Excluding import '__main__'
58381 INFO:   Removing import of __main__ from module pkg_resources
58382 INFO: Loading module hook "hook-pycparser.py"...
58383 INFO: Loading module hook "hook-pydoc.py"...
58385 INFO: Loading module hook "hook-pygments.py"...
60907 INFO: Loading module hook "hook-pytz.py"...
61021 INFO: Loading module hook "hook-setuptools.py"...
61812 INFO: Loading module hook "hook-sqlite3.py"...
61932 INFO: Loading module hook "hook-sysconfig.py"...
61935 INFO: Loading module hook "hook-xml.dom.domreg.py"...
61935 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
61936 INFO: Loading module hook "hook-xml.py"...
61938 INFO: Loading module hook "hook-_tkinter.py"...
62151 INFO: checking Tree
62151 INFO: Building Tree because Tree-00.toc is non existent
62152 INFO: Building Tree Tree-00.toc
62250 INFO: checking Tree
62250 INFO: Building Tree because Tree-01.toc is non existent
62251 INFO: Building Tree Tree-01.toc
62480 INFO: Looking for ctypes DLLs
62642 INFO: Analyzing run-time hooks ...
62659 INFO: Including run-time hook 'pyi_rth__tkinter.py'
62661 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
62666 INFO: Including run-time hook 'pyi_rth_pkgres.py'
62668 INFO: Including run-time hook 'pyi_rth_traitlets.py'
62669 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
62671 INFO: Including run-time hook 'pyi_rth_mpldata.py'
62673 INFO: Including run-time hook 'pyi_rth_certifi.py'
62713 INFO: Looking for dynamic libraries
64667 INFO: Looking for eggs
64667 INFO: Using Python library c:\users\sguser\appdata\local\programs\python\python38-32\python38.dll
64668 INFO: Found binding redirects:
[]
Traceback (most recent call last):
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\sguser\AppData\Local\Programs\Python\Python38-32\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\building\build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "C:\Users\sguser\Desktop\FoodNewsApp\main.spec", line 6, in <module>
    a = Analysis(['main.py'],
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
    self.__postinit__()
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
    for name, path, typecode in compile_py_files(new_toc, CONF['workpath']):
  File "c:\users\sguser\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\utils\misc.py", line 152, in compile_py_files
    with open(obj_fnm, 'rb') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '-'

C:\Users\sguser\Desktop\FoodNewsApp>

This happened to me when working on a recent project. I was running pyinstaller with a virtualenv enabled. When I deactivated the environment and tried it worked.

  1. deactivate the virtual environment
  2. Reinstall all the modules using pip
  3. Call pyinstaller (I used a spec file to define other things)

Here is a reference to the spec file I used in case it helps - https://github.com/karthiks3000/postman-doc-gen/blob/master/postman_doc_gen/postman_doc_gen.spec

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM