Py2exe, Runtimeerror with tweepy

2019-01-15 17:21发布

问题:

I wanted to use the python plugin for twitter called tweepy.

in my main.py file I just imported tweepy

import tweepy

My setup-file looks like this:

from distutils.core import setup
import py2exe
setup(
    windows=[{
        "script": 'main.py',
        }],
    options={
        "py2exe": {
            "includes": ["sip", "tweepy"]
        }
    }
)

When i execute python setupy.py py2exe via command line I get this repeating codeblock until I get an RuntimeError: maximum recursion depth exceeded in comparison.

File "C:\Python34\lib\site-packages\py2exe\hooks.py", line 291, in __getattr__
    self.__finder.safe_import_hook(renamed, caller=self)
  File "C:\Python34\lib\site-packages\py2exe\mf3.py", line 138, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:\Python34\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
    module = self._gcd_import(name)
  File "C:\Python34\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
    return self._find_and_load(name)
  File "C:\Python34\lib\site-packages\py2exe\mf3.py", line 298, in _find_and_load
    getattr(parent_module, name.rpartition('.')[2])

Does anyone knows a way to break out of this cycle?

回答1:

There seems to be a bug in the 0.9.2.2 version of py2exe where the module six.moves.urllib.parse gets into an infinite recursion loop until it reaches the maximum depth.

One way to go around it, if you don't really need the module, is to exclude the module in your setup.py:

options={
    "py2exe": {
        "includes": ["sip", "tweepy"],
        "excludes": ["six.moves.urllib.parse"]
    }
}