'Error occurred while building exe for py using Pyinstaller/Auto-py-to-exe
I am having an issue converting my python code to an exe, I tried upgrading pyinstaller and auto-py-to-exe but was of no avail. The code uses the following packages
import time
import pytube
import os
import cv2
from pynput.keyboard import Key, Controller
from moviepy.video.io.VideoFileClip import VideoFileClip
from playsound import playsound
import threading
import keyboard as press
import sys
and it works fine without any errors as a python file.
Here's the auto-py-to-exe's log/output:
Running auto-py-to-exe v2.18.2
Building directory: C:\Users\Alvin\AppData\Local\Temp\tmpnsrjw_95
Provided command: pyinstaller --noconfirm --onefile --console --icon "C:/Users/Alvin/Downloads/mask.ico" "C:\Users\Alvin\PycharmProjects\Computer\Corona Protek.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --console --icon C:/Users/Alvin/Downloads/mask.ico C:\Users\Alvin\PycharmProjects\Computer\Corona Protek.py --distpath C:\Users\Alvin\AppData\Local\Temp\tmpnsrjw_95\application --workpath C:\Users\Alvin\AppData\Local\Temp\tmpnsrjw_95\build --specpath C:\Users\Alvin\AppData\Local\Temp\tmpnsrjw_95
347654 INFO: PyInstaller: 4.10
347659 INFO: Python: 3.9.2rc1
347661 INFO: Platform: Windows-10-10.0.19041-SP0
347668 INFO: wrote C:\Users\Alvin\AppData\Local\Temp\tmpnsrjw_95\Corona Protek.spec
347679 INFO: UPX is not available.
347686 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Alvin\\PycharmProjects\\Computer']
350135 INFO: checking Analysis
350139 INFO: Building Analysis because Analysis-00.toc is non existent
350159 INFO: Initializing module dependency graph...
350193 INFO: Caching module graph hooks...
350232 INFO: Analyzing base_library.zip ...
358196 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
358205 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib'
368846 INFO: Caching module dependency graph...
369340 INFO: running Analysis Analysis-00.toc
369388 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Users\Alvin\AppData\Local\Programs\Python\Python39\python.exe
369553 INFO: Analyzing C:\Users\Alvin\PycharmProjects\Computer\Corona Protek.py
372020 INFO: Processing pre-safe import module hook six.moves from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
398533 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
400838 INFO: Processing pre-find module path hook site from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
400845 INFO: site: retargeting to fake-dir 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\fake-modules'
428081 INFO: Processing pre-safe import module hook win32com from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
497644 INFO: Processing module hooks...
497650 INFO: Loading module hook 'hook-appdirs.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
497673 INFO: Loading module hook 'hook-certifi.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
497690 INFO: Loading module hook 'hook-cv2.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
497703 INFO: Loading module hook 'hook-eel.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
498565 INFO: Loading module hook 'hook-imageio.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
498584 INFO: Loading module hook 'hook-imageio_ffmpeg.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
498594 INFO: Loading module hook 'hook-IPython.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
499828 INFO: Import to be excluded not found: 'PySide'
499853 INFO: Import to be excluded not found: 'gtk'
499870 INFO: Loading module hook 'hook-jedi.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
503502 INFO: Loading module hook 'hook-jinja2.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
503509 INFO: Loading module hook 'hook-openpyxl.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
503872 INFO: Loading module hook 'hook-parso.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
503931 INFO: Loading module hook 'hook-pycparser.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
503939 INFO: Loading module hook 'hook-pynput.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
504551 INFO: Loading module hook 'hook-pytest.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
506964 INFO: Loading module hook 'hook-pythoncom.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
508750 INFO: Loading module hook 'hook-pywintypes.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
510525 INFO: Loading module hook 'hook-regex.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
510542 INFO: Loading module hook 'hook-win32com.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
512423 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
512444 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
512459 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
512480 INFO: Loading module hook 'hook-django.core.mail.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
512559 INFO: Loading module hook 'hook-django.db.backends.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
516778 WARNING: Hidden import "django.db.backends.__pycache__.base" not found!
516786 INFO: Loading module hook 'hook-django.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
530366 INFO: Determining a mapping of distributions to packages...
702921 INFO: Packages required by django:
[]
746799 INFO: Loading module hook 'hook-django.template.loaders.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
747038 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
747229 INFO: Loading module hook 'hook-gevent.py' from 'C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
An error occurred while packaging
Traceback (most recent call last):
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\auto_py_to_exe\packaging.py", line 131, in package
run_pyinstaller()
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\building\build_main.py", line 803, in main
build(specfile, distpath, workpath, clean_build)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\building\build_main.py", line 725, in build
exec(code, spec_namespace)
File "C:\Users\Alvin\AppData\Local\Temp\tmpnsrjw_95\Corona Protek.spec", line 7, in <module>
a = Analysis(['C:\\Users\\Alvin\\PycharmProjects\\Computer\\Corona Protek.py'],
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\building\build_main.py", line 277, in __init__
self.__postinit__()
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\building\datastruct.py", line 155, in __postinit__
self.assemble()
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\building\build_main.py", line 445, in assemble
self.graph.process_post_graph_hooks(self)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\depend\analysis.py", line 326, in process_post_graph_hooks
module_hook.post_graph(analysis)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\depend\imphook.py", line 398, in post_graph
self._load_hook_module()
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\depend\imphook.py", line 361, in _load_hook_module
self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\compat.py", line 641, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 469, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 969, in load_module
File "<frozen importlib._bootstrap_external>", line 794, in load_module
File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks\hook-gevent.py", line 16, in <module>
datas, binaries, hiddenimports = collect_all(
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 1081, in collect_all
hiddenimports = collect_submodules(package_name, filter=filter_submodules)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 564, in collect_submodules
names = exec_statement(
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 91, in exec_statement
return __exec_statement(statement, capture_stdout=True)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 75, in __exec_statement
return __exec_python_cmd(cmd, capture_stdout=capture_stdout)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 66, in __exec_python_cmd
txt = compat.exec_python(*cmd, env=pp_env)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\compat.py", line 581, in exec_python
return exec_command(*cmdargs, **kwargs)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\compat.py", line 367, in exec_command
out = proc.communicate(timeout=60)[0]
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1134, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Users\Alvin\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1510, in _communicate
raise TimeoutExpired(self.args, orig_timeout)
subprocess.TimeoutExpired: Command '('C:\\Users\\Alvin\\AppData\\Local\\Programs\\Python\\Python39\\python.exe', '-c', '\nimport sys\nimport pkgutil\nimport traceback\n\n# ``pkgutil.walk_packages`` does not walk subpackages of zipped files per https://bugs.python.org/issue14209.\n# This is a workaround.\ndef walk_packages(path=None, prefix=\'\', onerror=None):\n def seen(p, m={}):\n if p in m:\n return True\n m[p] = True\n\n for importer, name, ispkg in pkgutil.iter_modules(path, prefix):\n if not name.startswith(prefix):\n name = prefix + name\n yield importer, name, ispkg\n\n if ispkg:\n try:\n __import__(name)\n except ImportError:\n if onerror is not None:\n onerror(name)\n except Exception:\n if onerror is not None:\n onerror(name)\n else:\n traceback.print_exc(file=sys.stderr)\n print("collect_submodules: failed to import %r!" % name, file=sys.stderr)\n else:\n path = getattr(sys.modules[name], \'__path__\', None) or []\n\n # don\'t traverse path items we\'ve seen before\n path = [p for p in path if not seen(p)]\n\n # Use Py2 code here. It still works in Py3.\n for item in walk_packages(path, name+\'.\', onerror):\n yield item\n # This is the original Py3 code.\n #yield from walk_packages(path, name+\'.\', onerror)\n\nfor module_loader, name, ispkg in walk_packages([\'C:\\\\Users\\\\Alvin\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python39\\\\lib\\\\site-packages\\\\gevent\'], \'gevent.\'):\n print(\'\\n$_pyi:\' + name + \'*\')\n')' timed out after 60 seconds
Project output will not be moved to output folder
Complete.
I would like to add that I could create the exe but it had a runtime error(The same asked on stackoverflow) I modified the moviepy library because of that error and I fixed that referring to this Solution. After trying to rebuild my exe I encountered this pyinstaller error for the first time, so I tried to uninstall and reinstall the moviepy library to try to revert the changes but still faced the pyinstaller error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
