При упаковке произошла ошибка. Использование pyinstaller

#python-3.x #django

Вопрос:

Я пытаюсь встроить файл python в исполняемый файл. Я не понимаю этого, так как в некоторые дни он строится, а в другие выдает ошибки. Скрипт python работает нормально, когда я запускаю его в CMD или визуальном коде.

Я пытался :

  • Переустановка Django
  • Переустановка Python
  • Переустановка auto-py-в-exe
  • Установка GDAL
  • Запуск CMD от имени администратора

Ошибка, возникающая при попытке создать исполняемый файл :

 Running auto-py-to-exe v2.10.1
Building directory: C:UserswhiteAppDataLocalTemptmphwzenqcz
Provided command: pyinstaller --noconfirm --onefile --console  "C:/Users/white/Desktop/Security/password.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --console C:/Users/white/Desktop/Security/password.py --distpath C:UserswhiteAppDataLocalTemptmphwzenqczapplication --workpath C:UserswhiteAppDataLocalTemptmphwzenqczbuild --specpath C:UserswhiteAppDataLocalTemptmphwzenqcz

4527 INFO: PyInstaller: 4.5.1
4542 INFO: Python: 3.9.7
4563 INFO: Platform: Windows-10-10.0.22000-SP0
4573 INFO: wrote C:UserswhiteAppDataLocalTemptmphwzenqczpassword.spec
4576 INFO: UPX is not available.
4590 INFO: Extending PYTHONPATH with paths
['C:\Users\white\Desktop\Security',
 'C:\Users\white\AppData\Local\Temp\tmphwzenqcz']
4794 INFO: checking Analysis
4796 INFO: Building Analysis because Analysis-00.toc is non existent
4812 INFO: Initializing module dependency graph...
4830 INFO: Caching module graph hooks...
4853 INFO: Analyzing base_library.zip ...
6467 INFO: Processing pre-find module path hook distutils from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
6475 INFO: distutils: retargeting to non-venv dir 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib'
8715 INFO: Caching module dependency graph...
8863 INFO: running Analysis Analysis-00.toc
8876 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:UserswhiteAppDataLocalProgramsPythonPython39python.exe
8926 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of C:UserswhiteAppDataLocalProgramsPythonPython39python39.dll
8934 INFO: Analyzing C:UserswhiteDesktopSecuritypassword.py
9313 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-urllib3.packages.six.moves.py'.
15327 INFO: Processing pre-find module path hook site from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
15330 INFO: site: retargeting to fake-dir 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\fake-modules'
25292 INFO: Processing module hooks...
25311 INFO: Loading module hook 'hook-certifi.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
25329 INFO: Loading module hook 'hook-Crypto.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
25347 INFO: Loading module hook 'hook-cryptography.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
25523 INFO: Loading module hook 'hook-eel.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
25616 INFO: Loading module hook 'hook-lz4.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
25631 INFO: Loading module hook 'hook-pycparser.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
25633 INFO: Loading module hook 'hook-difflib.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
25637 INFO: Loading module hook 'hook-distutils.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
25646 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
25664 INFO: Loading module hook 'hook-django.core.cache.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
25770 INFO: Loading module hook 'hook-django.core.mail.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
25807 INFO: Loading module hook 'hook-django.core.management.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
26521 INFO: Import to be excluded not found: 'matplotlib'
26529 INFO: Loading module hook 'hook-django.db.backends.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
27015 WARNING: Hidden import "django.db.backends.__pycache__.base" not found!
27020 INFO: Loading module hook 'hook-django.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
30750 INFO: Determining a mapping of distributions to packages...
37528 INFO: Packages required by django:
['sqlparse', 'tzdata', 'asgiref']
41420 INFO: Loading module hook 'hook-django.template.loaders.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
41497 INFO: Loading module hook 'hook-encodings.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
41553 INFO: Loading module hook 'hook-gevent.py' from 'C:\Users\white\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks'...
An error occurred while packaging
Traceback (most recent call last):
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesauto_py_to_exepackaging.py", line 131, in package
    run_pyinstaller()
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstaller__main__.py", line 126, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstaller__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerbuildingbuild_main.py", line 815, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerbuildingbuild_main.py", line 762, in build
    exec(code, spec_namespace)
  File "C:UserswhiteAppDataLocalTemptmphwzenqczpassword.spec", line 7, in <module>
    a = Analysis(['C:/Users/white/Desktop/Security/password.py'],
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerbuildingbuild_main.py", line 294, in __init__
    self.__postinit__()
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerbuildingdatastruct.py", line 159, in __postinit__
    self.assemble()
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerbuildingbuild_main.py", line 473, in assemble
    self.graph.process_post_graph_hooks(self)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerdependanalysis.py", line 373, in process_post_graph_hooks
    module_hook.post_graph(analysis)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerdependimphook.py", line 451, in post_graph
    self._load_hook_module()
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerdependimphook.py", line 408, in _load_hook_module
    self._hook_module = importlib_load_source(
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallercompat.py", line 632, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 1029, in load_module
  File "<frozen importlib._bootstrap_external>", line 854, 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 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerhookshook-gevent.py", line 16, in <module>
    datas, binaries, hiddenimports = collect_all(
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerutilshooks__init__.py", line 1156, in collect_all
    hiddenimports = collect_submodules(package_name,
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerutilshooks__init__.py", line 597, in collect_submodules
    names = exec_statement("""
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerutilshooks__init__.py", line 98, in exec_statement
    return __exec_statement(statement, capture_stdout=True)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerutilshooks__init__.py", line 79, in __exec_statement
    return __exec_python_cmd(cmd, capture_stdout=capture_stdout)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallerutilshooks__init__.py", line 70, in __exec_python_cmd
    txt = compat.exec_python(*cmd, env=pp_env)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallercompat.py", line 565, in exec_python
    return exec_command(*cmdargs, **kwargs)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsite-packagesPyInstallercompat.py", line 332, in exec_command
    out = proc.communicate(timeout=60)[0]
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsubprocess.py", line 1134, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "C:UserswhiteAppDataLocalProgramsPythonPython39libsubprocess.py", line 1510, in _communicate
    raise TimeoutExpired(self.args, orig_timeout)
subprocess.TimeoutExpired: Command '('C:\Users\white\AppData\Local\Programs\Python\Python39\python.exe', '-c', 'nimport sysnimport pkgutilnimport tracebacknn# ``pkgutil.walk_packages`` doesn't walk subpackages of zipped filesn# per https://bugs.python.org/issue14209. This is a workaround.ndef walk_packages(path=None, prefix='', onerror=None):n    def seen(p, m={}):n        if p in m:n            return Truen        m[p] = Truenn    for importer, name, ispkg in pkgutil.iter_modules(path, prefix):n        if not name.startswith(prefix):   ## Addedn            name = prefix   name          ## Addedn        yield importer, name, ispkgnn        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!" %n                          name, file=sys.stderr)n            else:n                path = getattr(sys.modules[name], '__path__', None) or []nn                # don't traverse path items we've seen beforen                path = [p for p in path if not seen(p)]nn                ## Use Py2 code here. It still works in Py3.n                for item in walk_packages(path, name '.', onerror):n                    yield itemn                ## This is the original Py3 code.n                #yield from walk_packages(path, name '.', onerror)nnfor module_loader, name, ispkg in walk_packages(['C:\\Users\\white\\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.```
 

Ответ №1:

Не бери в голову, я все понял! Проблема заключалась в том, что защитник Windows заблокировал файл при его создании.