pyinstaller 创建 EXE 运行时错误:调用 Python 对象时超出了最大递归深度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38977929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:43:14  来源:igfitidea点击:

pyinstaller creating EXE RuntimeError: maximum recursion depth exceeded while calling a Python object

pythonrecursionscipyexepyinstaller

提问by H_Four

I am running WinPython 3.4.4.3 with pyinstaller 3.2 (obtained via pip install pyinstaller).

我正在使用 pyinstaller 3.2(通过 pip install pyinstaller 获得)运行 WinPython 3.4.4.3。

Now I've got some really simple Qt4 code that I want to convert to EXE and I've run into problem that I cannot solve.

现在我有一些非常简单的 Qt4 代码,我想将其转换为 EXE,但遇到了无法解决的问题。

The Code:

编码:

import sys
import math
from PyQt4 import QtGui, QtCore 
import SMui
import numpy as np
from scipy.interpolate import InterpolatedUnivariateSpline

class SomeCalculation(QtGui.QMainWindow, SMui.Ui_MainWindow):
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.setWindowTitle('Some Calculation')
        self.calculate.clicked.connect(self.some_math)

    def some_math(self):
        a_diameter=self.a_diameter.value()
        b_diameter=self.b_diameter.value()
        complement=self.complement.value()
        angle=self.angle.value()
        preload=self.preload.value()

### ONLY MATH HAPPENS HERE also defining X and Y ####

        interpolator = InterpolatedUnivariateSpline(X, Y)

### MORE MATH HAPPENS HERE ####

        self.axial.setText(str(axial))
        self.radial.setText(str(radial))

def main():
    app = QtGui.QApplication(sys.argv)
    window=SomeCalculation()
    window.show()
    app.exec_()

if __name__=='__main__':
    main()

I try to run pyinstaller file_name.pyand I'm getting:

我试着跑pyinstaller file_name.py,我得到:

RuntimeError: maximum recursion depth exceeded while calling a Python object

Now if there's a few things that I have found out that also affect the issue:

现在,如果我发现一些事情也会影响这个问题:

1) If I comment out this line: from scipy.interpolate import InterpolatedUnivariateSpline

1)如果我注释掉这一行: from scipy.interpolate import InterpolatedUnivariateSpline

2) Creating EXE file from another different script that uses Scipy.Interpolate (RBS, but still) - works like a charm.

2)从另一个使用 Scipy.Interpolate(RBS,但仍然)的不同脚本创建 EXE 文件 - 就像一个魅力。

3) If I try to convert it to EXE using WinPython 3.5.1.1 + pyinstaller obtained the same way, and it's the same 3.2 version of it - it generates my exe file no problems.

3) 如果我尝试使用 WinPython 3.5.1.1 + pyinstaller 将其转换为 EXE,以相同的方式获得,并且它是相同的 3.2 版本 - 它生成我的 exe 文件没有问题。

I want to understand what's causing the error in the original case and I cannot find any answer on google unfortunately, most of the fixes I could find were related with matplotlib and not interpolation though.

我想了解是什么导致了原始案例中的错误,不幸的是我在谷歌上找不到任何答案,但我能找到的大多数修复都与 matplotlib 而不是插值相关。

回答by Aviral

This worked for me

这对我有用

  1. Run pyinstaller and stop it to generate the spec file :

    pyinstaller filename.py
    

    A file with .specas extension should be generated

  2. Now add the following lines to the beginning of the spec file :

    import sys
    sys.setrecursionlimit(5000)
    
  3. Now run the spec file using :

    pyinstaller filename.spec
    
  1. 运行 pyinstaller 并停止它以生成规范文件:

    pyinstaller filename.py
    

    .spec应生成扩展名为 as的文件

  2. 现在将以下行添加到规范文件的开头:

    import sys
    sys.setrecursionlimit(5000)
    
  3. 现在使用以下命令运行规范文件:

    pyinstaller filename.spec
    

回答by urxter

Mustafa did guide me to the right direction, you have to increase the recursion limit. But the code has to be put to the beginning of the spec file and not in your python code:

Mustafa 确实引导我走向正确的方向,你必须增加递归限制。但是代码必须放在规范文件的开头,而不是放在你的 python 代码中:

# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)

Create the spec file with pyi-makespecfirst, edit it and then build by passing the spec file to the pyinstallercommand. See the pyinstaller manual for more information about using spec files.

首先创建规范文件pyi-makespec,编辑它,然后通过将规范文件传递给pyinstaller命令来构建。有关使用规范文件的更多信息,请参阅 pyinstaller 手册。

Please make sure to use pyinstaller 3.2.0, with 3.2.1 you will get ImportError: cannot import name 'is_module_satisfies'(see the issueon GitHub)

请确保使用 pyinstaller 3.2.0,您将获得 3.2.1 ImportError: cannot import name 'is_module_satisfies'(请参阅GitHub 上的问题

回答by Mustafa Gondalwala

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

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

import sys
sys.setrecursionlimit(5000)

回答by user11855545

You can make changes to the recursion limit in the following manner:

您可以通过以下方式更改递归限制:

import sys
sys.setrecursionlimit(1000)

回答by Jae Hwan Kim

Even until March 2020, this issue has not been solved yet. As per some people's explanation, I increased setrecursionlimit in .spec file and tried to build it, but it did not work.

直到 2020 年 3 月,这个问题仍未得到解决。根据某些人的解释,我增加了 .spec 文件中的 setrecursionlimit 并尝试构建它,但它不起作用。

Through googling, I found out that this issue is caused by conflict of latest version of openpyxl and pyinstaller. Older version of openpyxl, such as 2.3.5 version, does not cause this issue.

通过谷歌搜索,我发现这个问题是由最新版本的openpyxl和pyinstaller冲突引起的。老版本的openpyxl,比如2.3.5版本,不会导致这个问题。

As such, solution for this issue is as follows.

因此,此问题的解决方案如下。

pip uninstall openpyxl
pip install openpyxl==2.3.5

回答by DovaX

Sometimes even the limit 5000 is not enough. It helped me to set limit to 20000. (in file 'filename.spec')

有时甚至限制 5000 是不够的。它帮助我将限制设置为 20000。(在文件“filename.spec”中)

import sys
sys.setrecursionlimit(20000)