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/site.py", line 548, in <module>
    main()
  File "/usr/local/lib/python2.7/site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/local/lib/python2.7/site.py", line 266, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/local/lib/python2.7/site.py", line 241, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/local/lib/python2.7/site.py", line 231, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
    return get_config_vars().get(name)
  File "/usr/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
    import re
  File "/usr/local/lib/python2.7/re.py", line 105, in <module>
    import sre_compile
  File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
    import sre_parse
  File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
    from sre_constants import *
  File "/usr/local/lib/python2.7/sre_constants.py", 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 sre_constants.py. So I changed the

from _sre import MAXREPEAT

To:


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

Hope that works for you!

4 comments:

  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.

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

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

      Delete