CentOS install Python 2.7

I wrote a bash script to install and compile Python 2.7 from source on my CentOS 5.5 x86_64 server. My  source of inspiration was an article from Villa Road.





  1. Olivier Refalo

    Found you post by chance… ran the script … it worked perfectly.

    Thank you!

    1. Happy to help!

  2. I’m having some trouble with this script.
    First of all the python alias doesn’t work. Only the python2.7 does work.
    Second of all when installing twisted/fabric or anything else that requires gcc to install itself it fails with the following message:

    gcc -pthread -shared build/temp.linux-x86_64-2.7/twisted/runner/portmap.o -L. -lpython2.7 -o build/lib.linux-x86_64-2.7/twisted/runner/portmap.so
    /usr/bin/ld: cannot find -lpython2.7
    collect2: ld returned 1 exit status
    error: command ‘gcc’ failed with exit status 1

    Can anyone help me solve this?

  3. Thanks, this made setup a lot quicker!

  4. @Omer Katz – not sure if you’re still having that issue (it has been months), but I just experienced the same problem. Adding this symlink fixed it for me:

    ln -sf /opt/python2.7.1/lib/libpython2.7.so /usr/lib/libpython2.7.so

  5. @Brandon – Thanks! that worked perfectly for me. I had followed the tutorial from Villa Road so, I just changed the python2.7.1 to python2.7

  6. @Brandon – thanks, that symlink did the trick for me too.

    I had tried adding my python lib path (/usr/local/python2.7.2/lib) to /etc/ld.so.conf and running ldconfig, but the psycopg2 install still couldn’t find -python2.7.

  7. Worked great for me, I had to run

    sudo yum install bzip2-devel

    before building python if you want to be able to install packages from pip with .tar.bz2 extension (most of em). this worked well for me with virtualenv on centos 6.5

    I also added

    ln -sf /opt/python2.7.1/lib/libpython2.7.so /usr/lib/libpython2.7.so

    right under the other ln part in your script.

    Thanks for this!

Leave a Reply

Your email address will not be published.