5

The py2exe worked quite well on the same py file several months ago. But when I tried it again today it failed by reporting a “RuntimeError: maximum recursion depth exceeded”. I got an empty “dist” folder as a result. The Py file works normally, it just can't be packaged. I guess there is something wrong with the imported modules in the py file. But I can not figure it out exactly. Does any one know the solution?

The begining part of my py file is:

import xlrd
import wx
import wx.lib.filebrowsebutton as filebrowse
from scipy.optimize import fsolve
import math
import threading
from sympy import Symbol
from sympy import solve

And the last several lines of the cmd window is:

File "D:\Python27\lib\site-packages\py2exe\mf.py", line 332, in _safe_import_hook
self.import_hook(name, caller, level=level)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook
return Base.import_hook(self,name,caller,fromlist,level)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 137, in import_hook
m = self.load_tail(q, tail)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 214, in load_tail
m = self.import_module(head, mname, m)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 724, in import_module
r = Base.import_module(self,partnam,fqname,parent)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 284, in import_module
m = self.load_module(fqname, fp, pathname, stuff)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 730, in load_module
r = Base.load_module(self, fqname, fp, pathname, (suffix, mode, typ))
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 314, in load_module
self.scan_code(co, m)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 423, in scan_code
self._safe_import_hook(name, m, fromlist, level=level)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 332, in _safe_import_hook
self.import_hook(name, caller, level=level)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook
return Base.import_hook(self,name,caller,fromlist,level)
File "D:\Python27\lib\site-packages\py2exe\mf.py", line 134, in import_hook
self.msg(3, "import_hook", name, caller, fromlist, level)
RuntimeError: maximum recursion depth exceeded

D:\Python27\py2exetemp>pause
shyuu
  • 123
  • 1
  • 1
  • 6

3 Answers3

14

I'd try to increase recursion depth limit. Insert at the beginning of your file:

import sys
sys.setrecursionlimit(5000)
Ihor Pomaranskyy
  • 5,437
  • 34
  • 37
0

This error can also occur when you have Jason path.py installed as described here: http://www.py2exe.org/index.cgi/PathModul. The solution from this page is to

Just rename

site-packages/path.py to

site-packages/jpath.py 

and make sure also to toggle your imports to

import jpath
Anna Christine
  • 860
  • 1
  • 6
  • 14
0

It works for Pyinstaller

Create a spec file

pyi-makespec options name.py 

Modify this spec by adding to start of file

import sys
sys.setrecursionlimit(5000) # or more

Build the executable file

pyi options name.spec 
Kirill Dolmatov
  • 327
  • 5
  • 11
  • 2
    The question is about py2exe not pyInstaller. This answer is off-topic. – master_gibber Jul 07 '17 at 16:16
  • @master_gibber this problem has the same decision for pyinstaller and py2exe as well. Because these two tools are substitute, I think it's better to post it here, instead of to create a new question-answer. – Kirill Dolmatov Jul 07 '17 at 16:22