Last Updated: February 25, 2016
· 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

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

tar -zxvf Python-2.7.3.tgz
cd Python-2.7.3
./configure --enable-shared --enable-unicode=ucs4
make altinstall

Sometimes your runtime linker won't have /usr/local/lib in the
default paths. You could edit the linker conf /etc/ 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

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