Last Updated: February 25, 2016
·
11.66K
· ajithhub

Building python altinstall

If you work on older linux distributions like centos 4 and 5 or
6, you find that the repositories never seem to have the latest
python (for good reasons, of course). You'll want to install a
new python without disturbing the rest of the system. You could
build it in your home dir or other nonstandard place with
configure --PREFIX=~/ or somesuch, but you'd rather put it
somewhere more useful.

If you build the altinstall target instead of just install it
will created the binary and lib dirs with the version in
/usr/local. This way you can choose which python you want at run
time.

I also want to build with a shared library so I can link against
python in my native programs. Also adding ucs4 support:

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -zxvf Python-2.7.3.tgz
cd Python-2.7.3
./configure --enable-shared --enable-unicode=ucs4
make
make altinstall

Sometimes your runtime linker won't have /usr/local/lib in the
default paths. You could edit the linker conf /etc/ld.so.conf or
rebuilt the python binary with the path.

I didn't know what the build command was for the python binary,
and I didn't want to mess witht he Makefile, so I just deleted
the python binary, and did another make. And then got this
command:

gcc -pthread  -Xlinker -export-dynamic \
    -o python Modules/python.o  -L. -lpython2.7 -lpthread \
    -ldl -lutil -lm

Now I just need to add the -Wl,-R /usr/local/lib flag

gcc -pthread  -Xlinker -export-dynamic \
    -Wl,-R /usr/local/lib \
    -o python Modules/python.o  -L. -lpython2.7 -lpthread \
    -ldl -lutil -lm