Python 2.7.5 installation on Ubuntu, MAXREPEAT

This has been asked a couple of times but the answers do not make any sense at least to me. I have Ubuntu 12.04 and had to upgrade Python from default (2.7.3?) to 2.7.5 to get libraries I can use to compile modwsgi.

I obtained 2.7.5 sources, configured with --enable-shared, made and installed. A few obsolete sun audio etc libraries could not be built but otherwise the installation went through. Except that it doesn't work:

visti@ubuntu:~$ python
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

The suggested solution here ubuntu ImportError: cannot import name MAXREPEAT was to reconfigure "virtualenv", whatever it is. /usr/local/bin has an ancient script named virtualenv but it tries to run python as well and doesn't work.

Someone suggested the problem might be related to using old Python modules as MAXREPEAT appeared in 2.7.4. To counter this I removed everything related to Python with rm -rf (/usr/bin/python*, /usr/lib/python*, /usr/local/lib/python*, /usr/local/bin/python*, did make clean, make, make install to 2.7.5.

Still the same result. Now I don't have a working version of Python anymore. Is there any way to fix this or should I try reinstalling Ubuntu Python packages if they have 2.7.5 available?

Hannu


Just battled the same problem. Ended up deleting the entire /usr/local/lib/python2.7 install path just to get back to the previous working version.

Also be sure to remove /usr/local/lib/python2.7-config, then reinstall python. Worked for me anyway.


This usually happens when you mix and match libpython.so versions with python interpreter versions. If nuking your install paths didnt help, check these environment variables. $PYTHONHOME $PYTHONINCLUDE $PYTHONLIB $PYTHONLIBSTATIC $PYTHONPATH Make sure what they point to were all deleted as well. And then reinstall.

You can also try and install python to a home directory, by configuring the -prefix variable to point to a home dir.

make configure -prefix=$HOME/mypython`

Then make sure you set those above variables to the new home directory python resides in.


The way I fixed this was by searching my system for other instances of the sre_constants.py file. Then see if the location of those files is referenced in your user or system $PATH . If so, remove that location configuration from your $PATH . Rerun python to see if that fixed it.

In my case, it seemed that Python is referencing the wrong location which does not does not support MAXREPEAT.

链接地址: http://www.djcxy.com/p/55070.html

上一篇: 如何在Python中对文件中的内容进行排序

下一篇: 在Ubuntu上安装Python 2.7.5,MAXREPEAT