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

10

41

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

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.

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.py and I'm getting:

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

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

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.

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.

Baldachin answered 16/8, 2016 at 14:44 Comment(1)
Did you ever solve this?Catania
C
86

This worked for me

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

    pyinstaller filename.py
    

    A file with .spec as 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
    
Condone answered 9/7, 2018 at 21:7 Comment(5)
Wondering why creators of pyinstaller do not give recursionlimit as a commnad-line option. Or at lease mention the problem in the FAQ somewhere.Rame
Thank you. Nothing on the internet worked for me except this!Brandnew
For me, it worked, but couldn't get any use of the EXE file. It runs but it will close afterward.Rhetoric
@Rhetoric open a terminal and run it from thereLamblike
I am getting that error all of a sudden. And I always used a specfile.Buzzard
A
34

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:

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

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

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 issue on GitHub)

Aggrieve answered 23/2, 2017 at 15:13 Comment(0)
M
8

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.

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.

As such, solution for this issue is as follows.

pip uninstall openpyxl
pip install openpyxl==2.3.5
Movable answered 19/3, 2020 at 11:13 Comment(0)
T
6

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

import sys
sys.setrecursionlimit(5000)
Tear answered 16/8, 2016 at 14:46 Comment(4)
Did that. Doesn't help.Baldachin
This seems to help for me, any idea why? Do you have a pointer?Orvieto
When I try to run a script from outside the package containing module, it errors out but if I call the script within the package it succeeds. Any idea ?Kelcy
This must be included at the top of the .spec file, not the python file.Fur
S
4

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

import sys
sys.setrecursionlimit(20000)
Selry answered 22/3, 2020 at 20:8 Comment(0)
L
1

make new environment with pipenv and install just the requirements package. (unused package which you have on your environment will cause the increase of the size of .exe file and make this error happen ) i try with python 3.8 and it worked

Lifeguard answered 24/7, 2020 at 0:14 Comment(0)
C
0

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

import sys
sys.setrecursionlimit(1000)
Chamberlain answered 18/8, 2019 at 7:26 Comment(0)
T
0

I was facing the same issue. I tried most of the things suggested here. But, I could not solve the issue on my laptop. What worked for me is summarized below:

  1. Open Anaconda prompt.
  2. Activate your environment using conda activate my_env.
  3. Navigate to your project folder from the Anaconda command prompt using cd your_folder_directory.
  4. Run pyinstaller --onefile my_python_file.py

This should not create any recursion error. This will create a dist folder in your project directory. Your executable will present in this folder.

Taeniafuge answered 29/7, 2020 at 4:46 Comment(0)
S
0

install pyinstaller last developer version:

pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Supersaturate answered 9/8, 2020 at 9:14 Comment(0)
P
0

Downgrade your pyinstaller to 5.6.2

First uninstall your current pyinstaller

pip uninstall pyinstaller

Install pyinstaller 5.6.2 version

pip install pyinstaller==5.6.2

This worked for me. Latest versions kept giving me the 'maximum recursion depth exceeded error' the moment i tried running my .exe

Plasma answered 14/5, 2023 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.