【问题标题】:Pyinstaller - ImportError: No system module 'pywintypes' (pywintypes27.dll)Pyinstaller - ImportError:没有系统模块'pywintypes'(pywintypes27.dll)
【发布时间】:2014-10-04 22:21:01
【问题描述】:

我正在尝试将我的 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会发生什么?
  • 我得到了与上面提到的完全相同的错误 1 ​​到 4 以及相同的警告,除了没有像以前那样说 4540 INFO: Hidden import 'netCDF4' has been found otherwise4540 INFO: Hidden import 'progressbar' has been found otherwise 的行。我还应该提到我正在使用 Anaconda 中包含的 python(这是我的默认 python 附加到我的路径)
  • 最奇怪的是我安装 pyinstaller 的方式与我的工作计算机相同,并在家里尝试了相同的命令(在相同的操作系统和 python 版本上也安装了 Anaconda,我现在有一个 .exe)介意您现在在运行可执行文件但开始时导入netCDF4 时遇到问题。不知道如何解释这些差异的原因......

标签: python exe pyinstaller


【解决方案1】:

我刚刚将 DLL pywintypes27.dll 复制到了 C:\Python27\Lib\site-packages\pywin32_system32
我在win32/lib 中添加了它。

没关系!

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。 dll pywintypes27.dll 位于 C:\Python27\Lib\site-packages\pywin32_system32 中。我将此目录添加到我的 PATH 环境变量中,并且 py2exe 能够找到 DLL。显然,设置路径不是正确的解决方案(您可以通过 os.environ 以编程方式进行),但是对我有用。

    【讨论】:

      【解决方案3】:

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

      在 python 2.7 上通过 conda 安装 pywin32 build 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/

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
      • 复制了链接中的答案。
      【解决方案4】:

      我使用的是虚拟环境并且遇到了同样的问题。 pywintypes35.dll 丢失。这是我的解决方案:

      pip install pypiwin32
      

      【讨论】:

        【解决方案5】:
        import win32api
        

        当我最近知道应该调用 win32api 以摆脱这个问题时,我也多次遇到这个模块未找到错误。一定要告诉你这个解决方案是否适合你

        【讨论】:

          【解决方案6】:

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

          错误 13 看起来像同一个错误。 This SO question 为我指明了正确的方向。本质上,安装MS VC++ 9.0 x64 redistribution package,这样就可以解决这些错误。

          按照 Lee 的建议,错误 2 似乎已得到解决。

          错误 4 是因为,由于某种原因,PyInstaller 在您的二进制列表中添加了一些空文件名。我不确定是否有更简单的方法来修复错误,但我可以通过放置来绕过它

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

          在我的规范文件中的 Analysis( ... ) 块之后。

          我不确定library python%s%s required via ctypes not found 警告是否相关。他们非常可疑,但我陷入了一个兔子洞,试图找出这些警告是在哪里产生的,结果只成功地浪费了我晚上大约两个小时。

          【讨论】:

            【解决方案7】:

            您应该使用“-install”参数运行 pywin32 扩展的安装后脚本,以确保环境设置正确。

            pywin32_postinstall.py -install

            【讨论】:

              【解决方案8】:

              我也遇到过类似的问题:

              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 选项的情况下重新安装有帮助。

              【讨论】:

                【解决方案9】:

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

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

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

                来源:https://programmersought.com/article/92924476575/

                祝你好运!!

                【讨论】:

                  【解决方案10】:

                  我使用的是 python 3.8 版,所以我正在复制以 38 结尾的文件(例如 xyz38.dll

                  1. 从网上下载并复制pythoncom38.dllpywintype38.dll到该位置:

                    C:\Users\hp\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\win32

                  注意:此位置可能因电脑而异,因此请转到该位置 在module pywintypespy_xyz not found错误中显示的错误。

                  (同时将两个 .dll 文件粘贴到该位置所有可用的 win32 文件夹中的 libs 或 Lib 或 lib 文件夹中)

                  1. 关闭 python 应用程序并重新启动并再次运行您的程序[工作 100%]

                  2. 如果上述方法不起作用,请在命令提示符下卸载 pypiwin32 pip uninstall pypiwin32 然后pip install pipiwin32 并重复第一步和第二步并重启你的电脑

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 2013-10-17
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-06-10
                    • 1970-01-01
                    相关资源
                    最近更新 更多