py2exe - No system module 'pywintypes'

sebo picture sebo · Oct 9, 2013 · Viewed 11.5k times · Source

I'm trying to convert a simple Python script into a Windows executable. My setup.py script is:

from distutils.core import setup
import py2exe

setup(
    name = "Simple Script",
    options = {
        "py2exe": {
            "dll_excludes" : ["libmmd.dll","libifcoremd.dll","libiomp5md.dll","libzmq.dll"]
        }
    },
    console=['simple_script.py']
)

I have added the dll_excludes as each one of them caused a failure. Now I've hit a failure that I can't simply exlude. This is the error trace:

Traceback (most recent call last):
  File "setup.py", line 12, in <module>
    console=['rules signed.py']
  File "C:\Anaconda\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Anaconda\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Anaconda\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Anaconda\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Anaconda\lib\site-packages\py2exe\build_exe.py", line 306, in _run
    self.plat_finalize(mf.modules, py_files, extensions, dlls)
  File "C:\Anaconda\lib\site-packages\py2exe\build_exe.py", line 1157, in plat_finalize
    import pythoncom
  File "C:\Anaconda\lib\site-packages\pythoncom.py", line 2, in <module>
    import pywintypes
  File "C:\Anaconda\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module>
    __import_pywin32_system_module__("pywintypes", globals())
  File "C:\Anaconda\lib\site-packages\win32\lib\pywintypes.py", line 98, in __import_pywin32_system_module__
    raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes27.dll)

I've installed pywin32 and tried excluding "pywintypes27.dll", "pywintypes", "pywin", "pywin.debugger" in my setup options, with no success. Also tried applying all other solutions I found on SO, such as moving "pythoncom27.dll", "pythoncomloader27.dll", and "pywintypes27.dll" to a top level directory.

Nothing has eliminated the "ImportError: No system module 'pywintypes' (pywintypes27.dll)" problem

Answer

Tompa picture Tompa · Nov 16, 2013

I recently installed Anaconda, partly because I need the win32com package, and don't want to exclude dll files. However, same problem for me.

Solution was to copy the DLL files:
pywintypes27.dll
pythoncom27.dll
sitting in:
C:\Anaconda\Lib\site-packages\win32
to
C:\Anaconda\Lib\site-packages\win32\lib

Because the function looking for those files look there but not in the directory above. Lots of comments in the source file pywintypes.py reveals there has been issues with this, probably due to different install procedures. I have posted an issue on the Anaconda issue tracker here.