py2exe fails with pandas import

2019-03-02 04:21发布

I have a python script that I want to make into an executable using py2exe. It fails when I try to import pandas (this is literally all I have in my example failing script):

import pandas

The traceback looks like:

File "c:\users\***\appdata\local\enthought\canopy\user\lib\site_packages\py2exe\mf.py", line 724, in import_hook return Base.import_hook(self,name,caller,fromlist,level)
RuntimeError: maximum recursion depth exceeded

I suspect that the problem may have something to do with the Canopy Python distribution, but I don't have an easy alternative to test.

Here is my setup file:

distutils.core.setup(
    options = {
        "py2exe": {
            "includes": ["pandas", "scipy"],
            "packages": ["matplotlib", "pytz"],
            "dll_excludes": ["MSVCP90.dll", ....],
        }
    }
    data_files=matplotlib.get_py2exe_datafiles(),
    windows=['just_pandas.py']
)

I have two questions. 1) Is there a way that I can make the pandas import work with py2exe? 2) If I can't fix this using the Canopy Python distribution, any suggestions for an alternative Python installation for Windows?

1条回答
甜甜的少女心
2楼-- · 2019-03-02 05:07

It turns out that the solution is just resetting the recursion limit. So I added these lines to my setup.py file:

import sys
sys.setrecursionlimit(3000)

Now the pandas import works just fine.

查看更多
登录 后发表回答