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

人盡茶涼 提交于 2019-12-18 21:49:15

问题


I am trying to package my python script into an executable. I thought I would be pretty straight forward as I don't have very many imports. First off here are my imports:

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

I know for a fact that numpy is supported I'm not sure about __future__ or os and I know for sure that netCDF4 and progressbar are not supported. I am using pyinstaller version 2.1 on Python 2.7.7 for Windows 7, and here is the command I use to start creating .exe:

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

Here is a list of errors. There seems to be one major problem with not being able to find the module pywintypes.dll, as well as two assemblies related to amd64_Microsoft. Here is a list of the 4 errors I get. How can I go about solving these?

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: ''

And here are the warnings I get that may or may not be relevent and are both related to not being able to find ctypes

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

The good news is that its seems the third party modules are being accounted for however I am not sure if they are associated with the errors that I am gettting:

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

回答1:


I just copied the DLL pywintypes27.dll in C:\Python27\Lib\site-packages\pywin32_system32.
I added it in win32/lib.

It's OK!




回答2:


I had the same problem. The dll, pywintypes27.dll was in C:\Python27\Lib\site-packages\pywin32_system32. I added this directory to my PATH environment variable and py2exe was able to find the DLL. Obviously, setting the path is not the correct solution (and you could possibly do it programatically via os.environ), but, works for me.




回答3:


Solution to prob 2. The solution in the link below solved the issue for me :)

With pywin32 build 219 installed via conda on python 2.7, importing pythoncom fails with

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

The issue is that the library pywintypes27.dll is stored not in

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

but in

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

Adding in the file win32\lib\pywintypes.py the elif part herebelow solves the issue

:::python

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)

In short terms it looks like pywintypes27.dll is located in the wrong folder

http://sourceforge.net/p/pywin32/bugs/685/




回答4:


I was using a virtual env and had the same problem. The pywintypes35.dll was missing. This was my solution:

pip install pypiwin32



回答5:


Not sure if you're still looking for help on this.

Errors 1 and 3 look like the same error. This SO question pointed me in the right direction. Essentially, install the MS VC++ 9.0 x64 redistribution package, and that should take care of those errors.

Error 2 appears to have been taken care of by following Lee's suggestion.

Error 4 is because, for some reason, PyInstaller stuck some empty file names in your binary list. I'm not sure if there's a less-hacky way to fix the error, but I was able to get around it by putting

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

after the Analysis( ... ) block in my spec file.

I'm not sure if the library python%s%s required via ctypes not found warnings are relevant. They're awfully suspicious, but I went down a rabbit hole trying to figure out where those warnings were generated and only succeeded in wasting about two hours of my evening.




回答6:


You should run post-install script for the pywin32 extensions with a '-install' parameter, to ensure the environment is setup correctly.

pywin32_postinstall.py -install




回答7:


I had a similar problem:

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.

My mistake was that I installed pywin32 via pip for user

pip install pywin32 --user

So the needed DLLs were in user's AppData: %appdata%\Python\Python27\site-packages That's why pywin32_postinstall.py couldn't find them.

Re-installing without --user option helped.



来源:https://stackoverflow.com/questions/25254285/pyinstaller-importerror-no-system-module-pywintypes-pywintypes27-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!