py2exe - No system module 'pywintypes'

前端 未结 4 1862
长情又很酷
长情又很酷 2021-02-20 05:33

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 =         


        
4条回答
  •  粉色の甜心
    2021-02-20 06:33

    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 "", line 1, in 
      File "C:\Program Files\Anaconda3\lib\site-packages\pythoncom.py", line 2, in 
        import pywintypes
      File "C:\Program Files\Anaconda3\lib\site-packages\win3\lib\pywintypes.py", line 124, in 
        __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]: 
    

    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.

提交回复
热议问题