user10026983
user10026983

Reputation: 81

Maximum recursion depth exceeded with pyinstaller in Python?

This is a common issue with certain libraries like pandas. I read that the solution may be by adding:

import sys
sys.setrecursionlimit(3000) 

in the setup.py .Where is this setup file? I have created the py file and located it in the directory that i want to turn to exe but i don't know where i should add that piece of code?

There is also this fix:

hook-pandas.py
hiddenimports = ['pandas._libs.tslibs.timedeltas',
'pandas._libs.tslibs.nattype',
'pandas._libs.tslibs.np_datetime',
'pandas._libs.skiplist']

but I don't know how to make this hook even though I read the post in the official site. If you can, make a clear answer about how to solve this.

Upvotes: 3

Views: 6455

Answers (4)

dreamwalkeranderson
dreamwalkeranderson

Reputation: 108

To supplement the answers by others for anyone attempting to increase the maximum recursion limit:

Use the import sys sys.setrecursionlimit(5000) snippet in the my_code.spec file, not your my_code.py file. Additionally, this file is re-written every time you run the pyinstaller command on a .py file, thus once you have edited it after an unsuccessful run, running pyinstaller my_code.py will take you back to square one.

Instead, run pyinstaller my_code.spec to keep your latest recursion limit setting.

Upvotes: 0

Alberto Garcia
Alberto Garcia

Reputation: 1

For me, it worked simply by adding the following lines at the beginning of the .spec file that pyinstaller creates:

import sys
sys.setrecursionlimit(2000)

Upvotes: 0

Mufeed
Mufeed

Reputation: 3218

You don't need add it to any special file.
Just add it into your current python file and run. You can see the difference by running getrecursionlimit() before and after running the command.

import sys
print(sys.getrecursionlimit())   # recursionlimit before 
# 1000
sys.setrecursionlimit(3000) 
print(sys.getrecursionlimit())    # recursionlimit after 
# 3000

Upvotes: 1

ShadowRanger
ShadowRanger

Reputation: 155546

setup.py files are created by you, to define the packaging information used for your project. I'd strongly recommend reading The Packaging Python Projects tutorial, as the topic is much larger than can be covered here.

All you do is add those lines to the top of your setup.py file, prior to any other imports (which might end up being monkeypatched by Pyinstaller, causing the problem).

Upvotes: 0

Related Questions