"maximum recursion depth exceeded" 用py2exe打包py文件时

"maximum recursion depth exceeded" while packaging py file with py2exe

几个月前,py2exe 在同一个 py 文件上运行良好。但是当我今天再次尝试时,它失败了,报告“RuntimeError: maximum recursion depth exceeded”。结果我得到了一个空的“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

命令的最后几行window是:

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

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

import sys
sys.setrecursionlimit(5000)

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

Just rename

site-packages/path.py to

site-packages/jpath.py 

and make sure also to toggle your imports to

import jpath

适用于 Pyinstaller

创建 spec 文件

pyi-makespec options name.py 

通过添加到文件开头来修改此规范

import sys
sys.setrecursionlimit(5000) # or more

构建可执行文件

pyi options name.spec