11

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

snapshoe
  • 13,454
  • 1
  • 24
  • 28
sebo
  • 1,584
  • 4
  • 16
  • 19
  • same problem here, when trying to use pywin32. maybe it is anaconda related, so I add this tag. Perhaps the anaconda mailing list would be a better place to ask this (unfortunately they do not use stackoverflow or an issue tracker at gihub for such questions/bugs). – bmu Oct 15 '13 at 13:10
  • 1
    Works OK for me with Anaconda-1.7.0-Windows-x86_64.exe and py2exe-0.6.10dev.win-amd64-py2.7.exe. – cgohlke Oct 16 '13 at 06:58
  • Try switching to PyInstaller. It's excellent. – cdonts Oct 17 '13 at 00:40

4 Answers4

20

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.

Tompa
  • 5,131
  • 2
  • 13
  • 13
  • This worked for me, but the relevant DLLs were in `C:\Users\Bob\AppData\Local\Continuum\Anaconda\Lib\site-packages\win32\lib` – Matt R Jun 24 '14 at 16:25
  • On Anaconda Python 3.4 the files are pywintypes34.dll and pythoncom34.dll and I found them in [my Anaconda folder]\Lib\site-packages\pywin32_system32. I'm trying to get py2exe working on python3 ... – flutefreak7 Sep 16 '14 at 19:21
1

Here is a code snippet of my daily use to package console python app to exe. It's works fine.

from distutils.core import setup
import py2exe
from glob import glob

data_files = [("Microsoft.VC90.CRT",
              glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')), 
             ... other required files]
py2exe_options={"py2exe":{"includes":[some_thing_need_to_included], 
                          "dll_excludes":[some_thing_need_to_exclude]}}
setup(data_files=data_files, 
      options=py2exe_options,
      console=['aim_python_script.py'])

You should check the content of your 'simple_script.py'. Does it reference some special third party library?

Erxin
  • 1,786
  • 4
  • 19
  • 33
1

I had a different problem with py2exe failing to find pywintypes27.dll - it was failing to find the file inside build_exe.isSystemDLL. The solution is to add the location of the DLLs in the path (at least the hack is to do so):

import site
for site_path in site.getsitepackages():
    pywin32_path = os.path.join(site_path, "pywin32_system32")
    if os.path.isdir(pywin32_path):
        os.environ["PATH"] = os.environ["PATH"] + ";" + pywin32_path
Lee Kamentsky
  • 631
  • 5
  • 6
1

There is a similar issue here: https://github.com/ContinuumIO/anaconda-issues/issues/37. I see you use Anaconda, and I think this is an issue with anaconda and the python interpreter.

Essentially, the issue is not present when using the IPython interpreter instead! Try for instance:

C:\...\User> python
>>>import pythoncom
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Anaconda3\lib\site-packages\pythoncom.py", line 2, in <module>
    import pywintypes
  File "C:\Program Files\Anaconda3\lib\site-packages\win3\lib\pywintypes.py", line 124, in <module>
    __import_pywin32_system_module__("pywintypes", globals())
  File "C:\Program Files\Anaconda3\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' (pywintypes34.dll)

On the other hand, try

C:\...\User> ipython
In [1]: import pythoncom

In [2]: pythoncom
Out[2]: <module 'pythoncom' from 'C:\\Program Files\\Anaconda3\\lib\\site-packages\\win32\\pythoncom34.dll'>

No problem when using IPython!

Son until this gets fixed, you can run your troublesome .py files using the IPython interpreter instead, eg:

C:\...\User> ipython setup.py

and that should work. You should seperate arguments you want to pass to your script from the command by a --, otherwise IPython might attempt to parse it, eg use:

C:\...\User> ipython setup.py -- arg1 arg2

Until this is fixed, try this method.

Ogaday
  • 469
  • 3
  • 13