Seite 1 von 1

Pyinstaller [WinError 1920]

Verfasst: Freitag 17. April 2020, 10:23
von Johnny Silver
Hi zusammen,

ich versuche eine .py in eine .exe umzuwandeln und möchte dafür pyinstaller verwenden. Dabei stoße ich immer auf folgendes Problem:

Code: Alles auswählen

Microsoft Windows [Version 10.0.18362.778]
(c) 2019 Microsoft Corporation. Alle Rechte vorbehalten.

C:\WINDOWS\system32>cd C:\Scripts

C:\Scripts>pyinstaller hello_world.py
156 INFO: PyInstaller: 3.6
156 INFO: Python: 3.7.7
156 INFO: Platform: Windows-10-10.0.18362-SP0
234 INFO: wrote C:\Scripts\hello_world.spec
234 INFO: UPX is not available.
249 INFO: Extending PYTHONPATH with paths
['C:\\Scripts', 'C:\\Scripts']
249 INFO: checking Analysis
249 INFO: Building Analysis because Analysis-00.toc is non existent
249 INFO: Initializing module dependency graph...
249 INFO: Caching module graph hooks...
265 INFO: Analyzing base_library.zip ...
3843 INFO: Processing pre-find module path hook   distutils
3843 INFO: distutils: retargeting to non-venv dir 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\\lib'
5968 INFO: Caching module dependency graph...
6203 INFO: running Analysis Analysis-00.toc
Traceback (most recent call last):
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
    yield
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\core\cffi\_dll.py", line 26, in _LoadLibraryEx
    function_name='LoadLibraryEx')
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\core\cffi\_util.py", line 81, in __call__
    self._raise_error(function_name)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\core\cffi\_util.py", line 92, in _raise_error
    raise exception
OSError: [WinError 1920] Das System kann auf die Datei nicht zugreifen

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\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\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "C:\Scripts\hello_world.spec", line 17, in <module>
    noarchive=False)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
    self.__postinit__()
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\building\build_main.py", line 395, in assemble
    redirects=self.binding_redirects)[1:])
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\depend\bindepend.py", line 228, in Dependencies
    for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\depend\bindepend.py", line 404, in getAssemblyFiles
    for assembly in getAssemblies(pth):
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\depend\bindepend.py", line 355, in getAssemblies
    res = GetManifestResources(pth)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\utils\win32\winmanifest.py", line 1007, in GetManifestResources
    return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\PyInstaller\utils\win32\winresource.py", line 170, in GetResources
    hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (1920, 'LoadLibraryEx', 'Das System kann auf die Datei nicht zugreifen')
Pyinstaller erstellt mir dann einen Build-Ordner, einen Dist Ordner und eine hello_world.spec Datei. Der Dist Ordner ist jedoch leer.

Ich habe schon einige Stunden Google-Suche hinter mir. Über die Sufu ließ sich auch nichts passendes zu meinem Problem finden. Kann mir jemand helfen?

Re: Pyinstaller [WinError 1920]

Verfasst: Freitag 17. April 2020, 10:34
von __deets__
Warum packst du deine Scripts in ein Verzeichnis direkt unter C:? Das ist ungewoehnlich, und auch wenn es nicht notwendigerweise das Problem behebt, wuerde ich das nicht ausschliessen wollen. Denn du hast ein Permission-Problem, und das ist kein Ort, wo du rumfuhrwerken solltest. *Kann* also Ursache sein.

Re: Pyinstaller [WinError 1920]

Verfasst: Freitag 17. April 2020, 10:56
von Johnny Silver
__deets__ hat geschrieben: Freitag 17. April 2020, 10:34 Warum packst du deine Scripts in ein Verzeichnis direkt unter C:?
Meine Scripts sind auf D:. In dem Fall habe ich es nur auf C: getestet und dafür einen Ordner erstellt. Verzweiflungstat, ich hab schon alles mögliche probiert was ich bei Google an Vorschlägen dazu finden konnte.

Das Problem tritt aber überall auf. Egal wo das Script gespeichert ist. Es kommt immer dieselbe Fehlermeldung.

Re: Pyinstaller [WinError 1920]

Verfasst: Freitag 17. April 2020, 12:01
von __deets__
Kann ein roter Hering sein, war ja auch nur eine Vermutung. Ich wuerde aber bei Windows zunehmend weniger ausserhalb der expliziten Userverzeichnisse machen. Und die dann eben ggf. nach D verschieben (mit enstprechender Umkofiguration).

Zu deinem Problem: der kriegt ja einen DLL nicht geladen, du kannst mal versuchen, eine logging/print-Ausgabe an der Stelle zu machen, wo das passiert. Also zB direkt vor

"C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32ctypes\core\cffi\_util.py", line 92,

Re: Pyinstaller [WinError 1920]

Verfasst: Freitag 17. April 2020, 12:31
von Johnny Silver
Sorry, leider weiß ich nicht wie ich eine logging/print-Ausgabe erstelle. Könntest du mir das erklären?

Re: Pyinstaller [WinError 1920]

Verfasst: Freitag 17. April 2020, 19:38
von __deets__
Indem du eine print-Anweisung da rein schreibst.

Code: Alles auswählen

print("hallo, das hier ist das einfachste Ding, das man in Python machen kann")
aber natuerlich mit der Variable.

Re: Pyinstaller [WinError 1920]

Verfasst: Montag 27. April 2020, 22:16
von timord

Code: Alles auswählen

C:\Users\padde\PycharmProjects\Twitter_Bot>python -m PyInstaller twitterbot.py
hallo, das hier ist das einfachste Ding, das man in Python machen kann
60 INFO: PyInstaller: 3.6
60 INFO: Python: 3.8.2
60 INFO: Platform: Windows-10-10.0.18362-SP0
61 INFO: wrote C:\Users\padde\PycharmProjects\Twitter_Bot\twitterbot.spec
62 INFO: UPX is not available.
62 INFO: Extending PYTHONPATH with paths
['C:\\Users\\padde\\PycharmProjects\\Twitter_Bot',
 'C:\\Users\\padde\\PycharmProjects\\Twitter_Bot']
62 INFO: checking Analysis
63 INFO: Building Analysis because Analysis-00.toc is non existent
63 INFO: Initializing module dependency graph...
65 INFO: Caching module graph hooks...
69 INFO: Analyzing base_library.zip ...
1571 INFO: Processing pre-find module path hook   distutils
1572 INFO: distutils: retargeting to non-venv dir 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64__qbz5n2kfra8p0\\lib'
2911 INFO: Caching module dependency graph...
2990 INFO: running Analysis Analysis-00.toc
Traceback (most recent call last):
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
    yield
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\core\ctypes\_util.py", line 42, in check_null
    raise make_error(function, function_name)
OSError: [WinError 1920] Das System kann auf die Datei nicht zugreifen.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\__main__.py", line 121, in <module>
    run()
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\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\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "C:\Users\padde\PycharmProjects\Twitter_Bot\twitterbot.spec", line 6, in <module>
    a = Analysis(['twitterbot.py'],
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
    self.__postinit__()
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\building\build_main.py", line 393, in assemble
    self.binaries.extend(bindepend.Dependencies([('', python, '')],
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\depend\bindepend.py", line 228, in Dependencies
    for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\depend\bindepend.py", line 404, in getAssemblyFiles
    for assembly in getAssemblies(pth):
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\depend\bindepend.py", line 355, in getAssemblies
    res = GetManifestResources(pth)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\utils\win32\winmanifest.py", line 1007, in GetManifestResources
    return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\PyInstaller\utils\win32\winresource.py", line 170, in GetResources
    hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\padde\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (1920, 'LoadLibraryExW', 'Das System kann auf die Datei nicht zugreifen.')
Hallo, ich bin neu hier habe aber den gleichen Fehler wie er!

Ich habe das print in die Datei eingefügt und wie man sieht, printet es das am Anfang auch. Die Frage die ich habe, was das zeigt und wie man das Problem lösen kann?

Ich hoffe auf eine schnelle Antwort! Danke.