Wednesday, 4 September 2013

Fixed! ImportError: cannot import name MAXREPEAT

Earlier today, I upgraded my Ubuntu box from 12.04 to 12.10. I noticed that Pidgin wouldn't launch so I opened up Terminal (ctrl+alt+t) and tried to run Pidgin through there. I noticed that I got the following stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/", line 548, in <module>
  File "/usr/local/lib/python2.7/", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/local/lib/python2.7/", line 266, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/local/lib/python2.7/", line 241, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/local/lib/python2.7/", line 231, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/local/lib/python2.7/", line 516, in get_config_var
    return get_config_vars().get(name)
  File "/usr/local/lib/python2.7/", line 449, in get_config_vars
    import re
  File "/usr/local/lib/python2.7/", line 105, in <module>
    import sre_compile
  File "/usr/local/lib/python2.7/", line 14, in <module>
    import sre_parse
  File "/usr/local/lib/python2.7/", line 17, in <module>
    from sre_constants import *
  File "/usr/local/lib/python2.7/", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

After some research, I found that I should run virtualenv. This did not work. Instead, I found a fix. It doesn't feel right but it's a fix none the less. If you look closely, you can see that the problem is that there is a field missing that needs to be accessed in So I changed the

from _sre import MAXREPEAT


        from _sre import MAXREPEAT
except ImportError:
        import _sre
        _sre.MAXREPEAT = 65535 # Oh man. I hate myself so much.

Hope that works for you!


  1. Thank you for this! I don't care how icky it is, it probably saved me an entire day of trying to work through the other suggested fixes out there.

  2. I don't understand where we must change this... in which file?
    Thank you in advance.

    1. You're very welcome!
      You change it in /usr/local/lib/python2.7/ .
      Hope this helps!