Feed on
Posts
Comments

if your python code produces the following error: “RuntimeError: maximum recursion depth exceeded in cmp,” try adding this line to the beginning of your code:

sys.setrecursionlimit(1500)

note that python’s default limit is 1000.


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

26 Responses to “fixing python error: RuntimeError: maximum recursion depth exceeded in cmp”

  1. on 20 May 2008 at 1:22 pm Python beginner

    Tip gorth gold =), thanks have had some trouble with this for a while, solved now, thanks!

  2. on 10 Oct 2008 at 1:18 am tom

    beautifull! Great Tip!

  3. on 28 Apr 2009 at 5:36 pm Jofish

    Sweet. Solved a problem I had been beating my head against that I was convinced was caused by something else.

    Thanks.

    Say hi to the ‘tvte for me.

    J

  4. on 28 May 2009 at 6:09 am Vasco Sousa

    HI

    I´m having the error you mencioned..

    Try to sove it the way you say, with “sys.setrecursionlimit(1500)” …

    But first tell me : name ‘sys’ is not defined…

    then i put import sys

    and the error continues..

    Can you help me?

    Thanks

  5. on 28 May 2009 at 6:23 am Vasco Sousa

    HI

    i raised the value and it blows up :)

    Thanks

  6. on 28 May 2009 at 8:38 am Vasco Sousa

    segmentation fault… :(

  7. on 11 Jul 2009 at 3:54 pm Homer

    When I tried this it said “NameError: name ‘sys’ is not defined”

  8. on 02 Dec 2009 at 1:28 pm zenome

    put:
    import sys
    at the start of ur code.. to solve the sys NameError

  9. on 01 Mar 2010 at 9:34 pm Tom Wright

    If you are getting segfaults after increasing the recursion limit, it means that your code is stuck in an endless loop.

  10. on 21 Jul 2010 at 8:30 am Shaz

    Good suggestion..thanks a lot..:)

  11. on 29 Oct 2010 at 12:37 pm Arnold

    Very great suggestion, i’ve modifying my code trying to solve that problem!
    Thanks!

  12. on 14 Sep 2011 at 3:35 am artw

    Thanks =D

  13. on 26 Sep 2011 at 9:38 pm Dave

    Fixed the problem with Jinja2 install on C:\Python27\Lib\distutils\log.py. Had to set to 2000

    What is the max value for setrecursionlimit still not working for Jinja2 install on
    File “c:\python27\lib\ntpath.py”, line 127, in splitdrive
    if p[1:2] == ‘:’:
    RuntimeError: maximum recursion depth exceeded in cmp

    New to python, trying to install flask

  14. on 18 Oct 2011 at 8:29 pm Alice Bevan-McGregor

    This is a mind-blastingly terrible idea.

    Recursion limits are there for a reason; if it’s being exceeded, something is wrong… very wrong! And that wrongness should be corrected the right way (fixing the recursion) not by telling Python to ignore the error.

    For any recursive problem there exists a non-recursive way to do it.

  15. on 05 Dec 2011 at 4:59 pm Jeff Hoogland

    Thanks for this quick and dirty hack, works like a charm.

    ~Jeff

  16. on 11 Dec 2011 at 3:37 am top mistakes

    Your blog is really cool to me and your topics are very relevant. I was browsing around and came across something you might find interesting. I was guilty of 3 of them with my sites. “99% of site owners are guilty of these 5 mistakes”. http://tinyurl.com/dxoyke8 You will be suprised how easy they are to fix.

  17. on 21 Dec 2011 at 5:59 am neha

    After importing the above line, my command is working but it is not generating any sequence diagram. Any idea why is it so?

  18. on 17 Jan 2012 at 10:27 pm Kusno

    where i can find the cmp? is this a file?

  19. on 17 Jan 2012 at 10:45 pm Kusno

    does it locate at /usr/bin?
    and how to edit it?

  20. on 26 Mar 2012 at 6:09 am Magesh

    wow.. thanks a lot

  21. on 22 Apr 2012 at 2:05 am Anuj

    Thanks a lot.. You save me big time

  22. on 19 Nov 2012 at 2:29 pm romeo

    thx a lot you’re great ! :)
    I look for the solution for a long time . you’re the best !

  23. on 27 Dec 2012 at 11:40 pm Anagha

    Thanks a tonne…

  24. on 06 Feb 2013 at 6:59 pm James lu

    what if I give it float(‘inf’)? ;)

  25. on 20 Jun 2014 at 11:57 am Jeremy

    Thanks a lot !!! Great tip !!

  26. on 21 Mar 2022 at 7:09 am W0TT

    878003 324935 There is noticeably a bundle to know about this. I assume you created certain nice points in functions also. 326630

Did I get this wrong? Let me know!

Trackback URI | Comments RSS