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

前端 未结 8 719
温柔的废话
温柔的废话 2021-01-11 18:03

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:

相关标签:
8条回答
  • 2021-01-11 18:45

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

    pip install pypiwin32
    
    0 讨论(0)
  • 2021-01-11 18:47

    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.

    0 讨论(0)
  • 2021-01-11 18:48

    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/

    0 讨论(0)
  • 2021-01-11 18:49

    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.

    0 讨论(0)
  • 2021-01-11 18:52

    Fix: No system module pywintypes (pywintypes39.dll).

    The first step is to open the Python installation directory and find the "pywin32_system32" folder

    The second step is to copy the entire folder to "project name\venv\Lib\site-packages"

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

    Good Luck!!

    0 讨论(0)
  • 2021-01-11 18:54

    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.

    0 讨论(0)
提交回复
热议问题