============================================================= A RecursionError (maximum recursion depth exceeded) occurred. For working around please follow these instructions ============================================================= 1. In your program's .spec file add this line near the top:: import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5) 2. Build your program by running PyInstaller with the .spec file as argument:: pyinstaller myprog.spec 3. If this fails, you most probably hit an endless recursion in PyInstaller. Please try to track this down has far as possible, create a minimal example so we can reproduce and open an issue at https://github.com/pyinstaller/pyinstaller/issues following the instructions in the issue template. Many thanks. Explanation: Python's stack-limit is a safety-belt against endless recursion, eating up memory. PyInstaller imports modules recursively. If the structure how modules are imported within your program is awkward, this leads to the nesting being too deep and hitting Python's stack-limit. With the default recursion limit (1000), the recursion error occurs at about 115 nested imported, with limit 2000 at about 240, with limit 5000 at about 660. Build exe failed!将带有torch库的Python文件转成exe,可以使用pyinstaller进行打包。
时间: 2023-08-09 15:08:16 浏览: 33
这个错误是由于递归层数过多导致的,可以尝试增加Python的递归深度限制来解决。
在你的程序的.spec文件中添加以下代码:
```
import sys
sys.setrecursionlimit(sys.getrecursionlimit() * 5)
```
这将把Python的递归深度限制增加5倍,从而减少递归层数过多导致的错误。
然后运行PyInstaller进行打包,命令如下:
```
pyinstaller your_file_name.spec
```
如果仍然出现错误,可能是由于PyInstaller的递归深度限制导致的,可以尝试使用最新版本的PyInstaller或者尝试减少程序中的递归层数来解决问题。如果仍然无法解决问题,请尝试创建一个最小化的示例程序并提交到PyInstaller的GitHub仓库中,以便开发者们帮助你解决问题。