Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Python 2.7.3 from source on a system with Python 2.7 already

I wish to compile Python 2.7.3 from source. The OS is OpenSUSE 11.4 x86_64, which already provides Python 2.7. I'd like to use 2.7.3 for the latest security patches, but it's a shared system so I can't tinker with the system Python interpreter.

I compile using ./configure --prefix=/opt/python --enable-shared. No configure errors, so I make. Again no errors. I do a make install (I don't think I need make altinstall, since this installation prefix in /opt/python isn't in use yet).

When I try to run the new binary /opt/python/bin/python, Python announces its version as 2.7, not 2.7.3. The only way I've found to correct this is to move the system's /usr/lib64/libpython2.7.so.1.0, and symlink it to /opt/python/lib/python/libpython2.7.so.1.0. This works and Python announces it is 2.7.3, but this breaks the system Python.

Is there anyway I can get the two to coexist, e.g. by getting the /opt/python to use its own libpython? Other than supplying LD_LIBRARY_PATH at runtime. Is there a compile time solution? Thanks.

like image 345
Dave Slanted Avatar asked Sep 23 '12 14:09

Dave Slanted


People also ask

Can you have Python 2 and 3 at the same time?

Yes you can . But, you need to set different environment variables for each of the version. If you don't want to do this,install anaconda distribution of python and create virtual env for different versions.

How do I convert Python2 to python3?

We can convert Python2 scripts to Python3 scripts by using 2to3 module. It changes Python2 syntax to Python3 syntax. We can change all the files in a particular folder from python2 to python3.

How do I use a specific version of Python?

As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed. You can also use commands like py -3.7 to select a particular version, or py --list to see which versions can be used.


1 Answers

To avoid having to specify the runtime library path using LD_LIBRARY_PATH each time Python is started, you can specify it at build time using the -rpath linker option:

./configure --enable-shared --prefix=/opt/python \
            LDFLAGS=-Wl,-rpath=/opt/python/lib
like image 183
user4815162342 Avatar answered Nov 04 '22 05:11

user4815162342