5

So i had python 2.7.2 on my server and i needed to update it to python 2.7.3. So i've tried to remove the 2.7.2 version and then install the new one using the sources. I wasn't able to remove the 2.7.2 version cause the system uses it to run crucial services on server, so i installed the 2.7.3 version in hope that after that i would be able to remove the old version. Still i cant remove the old version, although i'm able to execute the python 2.7.3 when i install any module i cant import it. I added the path to sys.path and i started finding the module but importing it causes another errors.

My python executes the /usr/local/bin/python which is the 2.7.3 version where the problems are. If i try to execute python like this /usr/bin/python it executes the old version and everything works fine there, i can import the new installed modules.

So what can i do to make python 2.7.3 work?

I've searched a lot of tutorials and tried things like add the library in .pth files on python and i started finding the modules but when importing it i get errors like this:

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
    import add_newdocs
  File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
    from type_check import *
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
    import multiarray
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString

Thanks for the help

EDIT PROBLEM SOLvED

So to solve the missing import modules i created a .pth file under /usr/local/lib/python2.7/site-packages/ with the directories where the python modules are and the python starts to find them. To fix the comptability problems you can install python from sources and specify the unicode doing ./configure --enable-unicode

more information here

3
  • Which version of Ubuntu exactly? And do you specifically need 2.7.3 or would a newer one like 2.7.5 work? Commented Oct 8, 2013 at 11:15
  • sudo apt-get install python2.7-dev? Commented Oct 8, 2013 at 11:19
  • $cat /etc/issue Ubuntu 11.10 Users asked for the 2.7.3 version but they said anything under 3.0 would do the work. At this point i would be happy if i get 2.7.5 doing everything right. python2.7-dev was already installed and didnt solve anything. Commented Oct 8, 2013 at 12:13

4 Answers 4

5

Do not EVER mess with system python, EVER.

What you should do is install python 2.7.3 with a --prefix into your home directory, then use virtualenv -p /home/myuser/path/to/python.

In any case, using virtualenv to run your own application is almost always a good idea, as it avoids polluting the system package directories with libraries you use in your own applications.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the idea i had already read about that but the problem is that i have to put the server working for people that is not so confortable with anything more than execute a python script doing python script_name
@JorgeSilva: then activate the virtualenv in their .bashrc
Seems like a good solution going to try it later at night, i'll reply with the results later. Thanks
pyenv is a better solution for managing several Python versions. virtualenv is better suited for handling package sets for a single version.
2

It looks like the modules you've installed were built against your old version of Python, or at least a version incompatible with your newer installation. The import error you're seeing at the bottom is the numpy module searching for a symbol that is not in your build of 2.7.3. There is further information here.

If possible, it's usually way easier to upgrade Python with a package manager. That way, if anything on your system depends on Python, but does not need exactly 2.7.2, then Python can be easily upgraded without disturbing anything. I'm guessing that either your server doesn't have a newer version of Python available and you can't add new repositories, or you don't have access to a package manager. If using packages is possible, I would go ahead and remove what you've built from source (the command should be 'make clean' if Python uses GNU Make).

If that isn't an option, then there should be a way to compile Python, but not install it into system directories. Then you could add a symlink for users, and make sure that symlink has precedence in their path.

1 Comment

Thanks to point out to the incompatible problems, i made a new installation using the other pyunicode and it solve the problem.
2

When installing python use the following steps
using prefix to specify the installation directory

 ./configure --prefix=/usr/bin/python
 make
 make install

Then everytime u run a new Terminal u have specify

export PATH="$PATH:/usr/bin/"

to tell where is the installation directory of Python

This way u can use any number of pythons

Comments

0

You can install python libs from R. It works for me.

For example, to install numpy library from R type:

system('python -m pip install -U numpy')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.