Pyinstaller - ImportError: 找不到系统模块'pywintypes' (pywintypes27.dll)。

12

我正在尝试将我的Python脚本打包成可执行文件。我认为这应该很简单,因为我没有太多的导入。首先,这里是我的导入:

from __future__ import print_function 
from netCDF4 import Dataset
import numpy as np
import os
from progressbar import Percentage,Bar,ETA,ProgressBar,RotatingMarker  

我知道numpy被支持,但不确定__future__os是否被支持。我可以确定netCDF4progressbar不受支持。我使用的是针对Windows 7的Python 2.7.7上的pyinstaller版本2.1,并且以下是我用于开始创建.exe文件的命令:

C:\Users\Patrick\Desktop\netcdf_grid_extraction>pyinstaller --onefile --hidden-i
mport=netCDF4 --hidden-import=progressbar netcdf_grid_extraction.py

这里有一份错误列表。似乎有一个主要问题是找不到模块pywintypes.dll,还有两个与amd64_Microsoft相关的程序集。这是我收到的4个错误列表。我该如何解决这些问题?

1

1130 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.
21022.8_none ...
1134 WARNING: Assembly not found
1134 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
not found
1210 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.
21022.8_none ...
1210 WARNING: Assembly not found
1210 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
not found

2

Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pythoncom.py", line 2, in <m
odule>
    import pywintypes
  File "C:\Users\Patrick\Anaconda\lib\site-packages\win32\lib\pywintypes.py", li
ne 124, in <module>
    __import_pywin32_system_module__("pywintypes", globals())
  File "C:\Users\Patrick\Anaconda\lib\site-packages\win32\lib\pywintypes.py", li
ne 98, in __import_pywin32_system_module__
    raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes27.dll)
4155 INFO: Processing hook hook-pywintypes
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pythoncom.py", line 2, in <m
odule>
    import pywintypes
  File "C:\Users\Patrick\Anaconda\lib\site-packages\win32\lib\pywintypes.py", li
ne 124, in <module>
    __import_pywin32_system_module__("pywintypes", globals())
  File "C:\Users\Patrick\Anaconda\lib\site-packages\win32\lib\pywintypes.py", li
ne 98, in __import_pywin32_system_module__
    raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes27.dll)

3

5840 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.
21022.8_none ...
5840 WARNING: Assembly not found
5840 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
not found

4

Traceback (most recent call last):
  File "C:\Users\Patrick\Anaconda\Scripts\pyinstaller-script.py", line 9, in <mo
dule>
    load_entry_point('PyInstaller==2.1', 'console_scripts', 'pyinstaller')()
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\main.py", line 88, in run
    run_build(opts, spec_file, pyi_config)
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\main.py", line 46, in run_build
    PyInstaller.build.main(pyi_config, spec_file, **opts.__dict__)
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 1924, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'
))
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 1873, in build
    execfile(spec)
  File "C:\Users\Patrick\Desktop\netcdf_grid_extraction\netcdf_grid_extraction.s
pec", line 17, in <module>
    console=True )
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 1170, in __init__
    strip_binaries=self.strip, upx_binaries=self.upx,
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 1008, in __init__
    self.__postinit__()
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 309, in __postinit__
    self.assemble()
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 1050, in assemble
    dist_nm=inm)
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 842, in checkCache
    digest = cacheDigest(fnm)
  File "C:\Users\Patrick\Anaconda\lib\site-packages\pyinstaller-2.1-py2.7.egg\Py
Installer\build.py", line 796, in cacheDigest
    data = open(fnm, "rb").read()
IOError: [Errno 22] invalid mode ('rb') or filename: ''

这里是我收到的警告,它们可能与 ctypes 无法找到有关,但也可能不相关。

890 WARNING: library python%s%s required via ctypes not found
2175 WARNING: library python%s%s required via ctypes not found

好消息是似乎第三方模块正在考虑在内,但我不确定它们是否与我获取的错误相关:

4540 INFO: Hidden import 'netCDF4' has been found otherwise
4540 INFO: Hidden import 'progressbar' has been found otherwise
4540 INFO: Hidden import 'codecs' has been found otherwise
4545 INFO: Hidden import 'encodings' has been found otherwise

如果你执行 C:\path\to\pyinstaller.py --onefile netcdf_grid_extraction.py 会发生什么? - Joran Beasley
我遇到了与上述1到4完全相同的错误,警告也一样,只是没有像之前那样出现“4540 INFO:已找到隐藏导入'netCDF4'”或“4540 INFO:已找到隐藏导入'progressbar'”这样的行。我还应该提到,我正在使用Anaconda中包含的Python(它是我的默认Python并附加到我的路径中)。 - pbreach
最奇怪的是,我以与工作电脑相同的方式安装了pyinstaller,并在家中尝试了相同的命令(在相同的操作系统和Python版本上也安装了Anaconda,现在我有一个.exe文件)。请注意,当可执行文件运行时,导入netCDF4没有任何问题,但这只是一个开始。不确定如何解释这些差异的原因... - pbreach
10个回答

11

我刚刚复制了DLL文件pywintypes27.dll到路径C:\Python27\Lib\site-packages\pywin32_system32中。
我将其添加到win32/lib中。

没问题!


7

我曾经遇到过相同的问题。 pywintypes27.dll文件在C:\ Python27 \ Lib \ site-packages \ pywin32_system32中。我将此目录添加到我的PATH环境变量中,然后py2exe就能找到这个DLL了。显然,设置路径不是正确的解决方案(你可以通过os.environ以编程方式进行设置),但对我来说有效。


6

问题2的解决方案。下面链接中的解决方案解决了我的问题 :)

使用通过conda在Python 2.7上安装的pywin32构建219时,导入pythoncom会失败

ImportError: No system module 'pywintypes' (pywintypes27.dll)

问题在于pywintypes27.dll库未存储在以下目录中:
pathtovenv\lib\site-packages\win32\lib\pywintypes27.dll

但是在

pathtovenv\lib\site-packages\win32\pywintypes27.dll

在文件win32\lib\pywintypes.py中添加下面的elif部分可以解决该问题。
if found is None:
    # Not in the Python directory?  Maybe we were installed via
    # easy_install...
    if os.path.isfile(os.path.join(os.path.dirname(__file__), filename)):
        found = os.path.join(os.path.dirname(__file__), filename)
    elif os.path.isfile(os.path.join(os.path.dirname(__file__), "..", filename)):
        found = os.path.join(os.path.dirname(__file__), "..", filename)

简而言之,看起来pywintypes27.dll文件位于错误的文件夹中。 http://sourceforge.net/p/pywin32/bugs/685/

虽然这个链接可能回答了问题,但最好在此处包含答案的基本部分并提供参考链接。如果链接页面更改,仅有链接的答案可能会失效。 - ekad
复制了链接中的答案。 - Nautilius

4
我正在使用虚拟环境,遇到了相同的问题。缺少pywintypes35.dll文件。这是我的解决方案:
pip install pypiwin32

1
import win32api

最近我多次遇到了这个模块未找到的错误,后来才知道需要调用win32api才能解决这个问题。如果这个解决方案对你有用,请告诉我。


0

不确定您是否仍在寻求此方面的帮助。

错误13看起来是相同的错误。这个SO问题指引了我正确的方向。基本上,安装MS VC++ 9.0 x64 redistribution package,那应该就可以解决这些错误了。

错误2似乎已经通过遵循李的建议得到解决。

错误4是因为,由于某种原因,PyInstaller将一些空文件名放入了您的二进制列表中。我不确定是否有更少hacky的方法来修复此错误,但我能够通过放置

for b in a.binaries:
    if b[0] == '':
        a.binaries.remove(b)

在我的规范文件中 Analysis(...) 段后。
我不确定 library python%s%s required via ctypes not found 警告是否相关。它们非常可疑,但我陷入了一个兔子洞,试图找出这些警告是如何生成的,并且只成功浪费了我晚上约两个小时的时间。

0

修复:没有系统模块pywintypes(pywintypes39.dll)。

第一步是打开Python安装目录并找到“pywin32_system32”文件夹。

images: https://istack.dev59.com/ERVu5.webp

第二步是将整个文件夹复制到“项目名称\venv\Lib\site-packages”中。

images: https://istack.dev59.com/P8JY0.webp

Sources:https://programmersought.com/article/92924476575/

祝你好运!


0
我正在使用Python 3.8版本,因此我正在复制以38结尾的文件(例如`xyz38.dll`)。
1. 从互联网下载并将`pythoncom38.dll`和`pywintypes38.dll`复制到以下位置:
C:\Users\hp\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\win32
注意:此位置可能因计算机而异,因此请转到在"module pywintypes"或"py_xyz not found"错误中显示的位置。
(还要在该位置所有win32文件夹内的libs、Lib或lib文件夹中粘贴这两个`.dll`文件)。
  • 关闭Python应用程序,然后重新启动并再次运行您的程序[百分之百有效]

  • 如果上述方法不起作用,请在命令提示符中卸载pypiwin32 pip uninstall pypiwin32 然后 pip install pipiwin32 并重复第1步和第2步,最后重新启动您的电脑


  • 0

    你应该使用 '-install' 参数运行 pywin32 扩展的 post-install 脚本,以确保环境设置正确。

    pywin32_postinstall.py -install


    0

    我有一个类似的问题:

    Traceback (most recent call last):
      File ".\install\pywin32_postinstall.py", line 605, in <module>
        install()
      File ".\install\pywin32_postinstall.py", line 328, in install
        LoadSystemModule(lib_dir, "pywintypes")
      File ".\install\pywin32_postinstall.py", line 166, in LoadSystemModule
        mod = imp.load_dynamic(modname, filename)
    ImportError: DLL load failed: The specified module could not be found.
    

    我的错误是我通过pip for user安装了pywin32

    pip install pywin32 --user
    

    所需的DLL文件位于用户的AppData目录下:%appdata%\Python\Python27\site-packages,这就是为什么pywin32_postinstall.py找不到它们的原因。

    重新安装时不要使用--user选项即可解决问题。


    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接