"超出最大递归深度"用py2exe打包py文件

时间:2015-03-23 13:44:44

标签: python python-2.7 recursion py2exe

几个月前,py2exe在同一个py文件上运行得很好。但是当我今天再次尝试它时,通过报告“RuntimeError:超出最大递归深度”失败了。结果我得到一个空的“dist”文件夹。 Py文件正常工作,它无法打包。我猜py文件中导入的模块有问题。但我无法弄明白。有人知道解决方案吗?

我的py文件的开头部分是:

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

cmd窗口的最后几行是:

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

3 个答案:

答案 0 :(得分:13)

我会尝试增加递归深度限制。在文件的开头插入:

import sys
sys.setrecursionlimit(5000)

答案 1 :(得分:0)

如果您按照此处所述安装了Jason path.py,也会发生此错误:http://www.py2exe.org/index.cgi/PathModul。此页面的解决方案是

  

只需重命名

site-packages/path.py to

site-packages/jpath.py 
     

并确保还要将导入切换为

import jpath

答案 2 :(得分:0)

适用于Pyinstaller

创建spec文件

pyi-makespec options name.py 

通过添加到文件开头

来修改此规范
import sys
sys.setrecursionlimit(5000) # or more

构建可执行文件

pyi options name.spec