Pyinstaller 不工作 - ImportError: Module 'pywintypes' is not in freeze sys.path

Posted

技术标签:

【中文标题】Pyinstaller 不工作 - ImportError: Module \'pywintypes\' is not in freeze sys.path【英文标题】:Pyinstaller not working - ImportError: Module 'pywintypes' isn't in frozen sys.pathPyinstaller 不工作 - ImportError: Module 'pywintypes' is not in freeze sys.path 【发布时间】:2021-09-12 21:08:14 【问题描述】:
C:\Users\CENSORED\AppData\Local\Programs\Python\Python37-32\ReworkX\dist\RAN_HelperTEST>RAN_HelperTEST.exe
Traceback (most recent call last): File
"PyInstaller\hooks\rthooks\pyi_rth_win32api.py", line 20, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in
exec_module File "pywintypes.py", line 136, in <module> File
"pywintypes.py", line 61, in __import_pywin32_system_module__
ImportError: Module 'pywintypes' isn't in frozen sys.path
['C:\\Users\\CENSORED\\AppData\\Local\\Programs\\Python\\Python37-32\\ReworkX\\dist\\RAN_HelperTEST\\base_library.zip',
'C:\\Users\\CENSORED\\AppData\\Local\\Programs\\Python\\Python37-32\\ReworkX\\dist\\RAN_HelperTEST\\lib-dynload',
'C:\\Users\\CENSORED\\AppData\\Local\\Programs\\Python\\Python37-32\\ReworkX\\dist\\RAN_HelperTEST']
[21672] Failed to execute script pyi_rth_win32api

以上是我尝试执行时的错误。在新的 dist 或创建的构建文件夹中的任何地方都没有 pyi_rth_win32api - 但它存在于\Lib\site-packages\PyInstaller\Hooks\rthooks

在 hooks 文件夹中创建该文件的日期是在我运行 pyinstaller 之后的今天,因此它在任何地方都不存在。为什么要创建它并尝试添加它并导致 pyinstaller 失败?

操作系统过时了吗?

在站点包中,有win32win32comwin32comextwin32ctypes 目录。

他们都没有pyi_rth_win32api

查看我第一次运行 Pyinstaller 时出现的文本,我注意到一些可能相关的警告?

如:

46049 WARNING: lib not found: pywintypes37.dll dependency of
c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\win32wnet.pyd
46081 WARNING: lib not found: pywintypes37.dll dependency of
c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\win32api.pyd
46187 WARNING: lib not found: pywintypes37.dll dependency of
c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\win32pdh.pyd

还有:

Traceback (most recent call last):   File "<string>", line 3, in
<module>   File
"c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\utils\win32\winutils.py",
line 97, in import_pywin32_module
    module_name, globals=, locals=, fromlist=[''])   File "c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\pythoncom.py",
line 2, in <module>
    import pywintypes   File "c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\lib\pywintypes.py",
line 136, in <module>
    __import_pywin32_system_module__("pywintypes", globals())   File "c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\lib\pywintypes.py",
line 64, in __import_pywin32_system_module__
    import _win32sysloader ImportError: DLL load failed: %1 is not a valid Win32 application. 44334 INFO: Loading module hook
'hook-pywintypes.py' from
'c:\\users\\CENSORED\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
Traceback (most recent call last):   File "<string>", line 3, in
<module>   File
"c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\utils\win32\winutils.py",
line 97, in import_pywin32_module
    module_name, globals=, locals=, fromlist=[''])   File "c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\lib\pywintypes.py",
line 136, in <module>
    __import_pywin32_system_module__("pywintypes", globals())   File "c:\users\CENSORED\appdata\local\programs\python\python37-32\lib\site-packages\win32\lib\pywintypes.py",
line 64, in __import_pywin32_system_module__
    import _win32sysloader ImportError: DLL load failed: %1 is not a valid Win32 application.

如果有人可以帮助我 - 我正在尝试创建一个可执行文件来与其他不使用 python 的工作用户共享我编写的脚本。

另外 - 脚本以用户输入行开头。不确定这是否相关?

【问题讨论】:

【参考方案1】:

您的应用程序缺少一个 dll 文件:pywintypes37.dll

【讨论】:

以上是关于Pyinstaller 不工作 - ImportError: Module 'pywintypes' is not in freeze sys.path的主要内容,如果未能解决你的问题,请参考以下文章

使用 PyQt5 构建并由 pyinstaller 编译的 GUI 无法正常工作 [不重复] [重复]

Pyinstaller 可执行文件不起作用

Python 脚本在定期运行时工作正常,但在使用 PyInstaller 编译时不能正常运行

PyInstaller exe仅与-F选项一起使用

想用pyinstaller打包成exe的运行文件,打包出来的exe文件会停止工作,怎么破?我安装的是Python3.7 64位

带有 Pyside2 和 Matplotlib 的 Pyinstaller 无法正常工作