How to install Python 2.7 and Python 3.3 on CentOS 6

This guide shows you how to install Python 2.7 and/or Python 3.3 on any version of CentOS 6. It also includes instructions for setuptools, pip, virtualenv and pyvenv.

In this guide I will show you how to install Python 2.7 and 3.3 on CentOS 6. The examples below are for Python 2.7.6 and Python 3.3.5, but the procedure is the same for any modern version of Python including the upcoming Python 3.4.0.

I make regular updates to this guide to track new versions. Please see the end of the document for a changelog.

CentOS 6 ships with Python 2.6.6 and several critical system utilities, for example yum, will break if the default Python interpreter is upgraded. The trick is to install new versions of Python in /usr/local (or some other non-standard location) so that they can live side-by-side with the system version.

This guide should work for all versions of CentOS 6, but I have only verified it on CentOS 6.5 64 bit. It will probably work for some versions of CentOS 5 also.

Execute all the commands below as root either by logging in as root or by using sudo.

Preparations – install prerequisites

In order to compile Python you must first install the development tools and a few extra libs. The extra libs are not strictly needed to compile Python but without them your new Python interpreter will be quite useless.

Things to consider

Before you compile and install Python there are a few things you should know and/or consider:


Python has a long and complicated history when it comes to Unicode support. Unless you have very specific reasons you should configure Python 3.2 and earlier to enable UTF-32 support. This increases memory usage but improves compatibility. In Python 3.3 the Unicode support has been completely rewritten and strings are automatically stored using the most efficient encoding possible.

You enable UTF-32 in Python 2.7 by adding --enable-unicode=ucs4 to the configure command. In Python 3.2 the flag is called --with-wide-unicode.

Shared library

You should probably compile Python as a shared library. All modern Linux distros ship with Python compiled as a shared library, and there are third-party tools such as mod_wsgi and Blender that won’t work without it. If you compile Python as a shared library you must also tell it how to find the library. You have two options:

  • Compile the path into the executable by adding this to the end of the configure command: LDFLAGS="-Wl,-rpath /usr/local/lib"
  • Open the file /etc/ in a text editor and add the path /usr/local/lib to the end of it. After you have added the line you must run /sbin/ldconfig to make the dynamic linker aware of the change. This is how the file will look after adding the line on a clean install of CentOS 6.5:

Use “make altinstall” to prevent problems

It is critical that you use make altinstall when you install your custom version of Python. If you use the normal make install you will end up with two different versions of Python in the filesystem both named python. This can lead to problems that are very hard to diagnose.

Download, compile and install Python

Here are the commands to download, compile and install Python. If you modify /etc/ as discussed above you can remove the LDFLAGS parameter below.

After running the commands above your newly installed Python interpreter will be available as /usr/local/bin/python2.7 or /usr/local/bin/python3.3. The system version of Python 2.6.6 will continue to be available as /usr/bin/python, /usr/bin/python2 and /usr/bin/python2.6.

Download and install Setuptools + pip

Setuptools has replaced Distribute as the official package manager used for installing packages from the Python Package Index. Each Python interpreter on your system needs its own install of Setuptools. I also suggest you install pip. It builds on top of Setuptools and provides a few extra functions that are useful when you manage your packages.

The instructions below will install the latest version of Setuptools and pip for you.

The packages will end up in /usr/local/lib/pythonX.Y/site-packages/ (where X.Y is the Python version).

What’s next?

If you are using Python 2.7 I strongly recommend that you install virtualenv and learn how to use it. Virtualenv makes it possible to create isolated Python environments. If you are using Python 3.3 then you don’t need virtualenv because that functionality is already built in.

Each isolated Python environment (also called sandbox) can have its own Python version and packages. This is very useful when you work on multiple projects or on different versions of the same project.

Create your first isolated Python environment

When you use virtualenv to create a sandbox it will automatically install setuptools and pip for you inside the sandbox. If you use pyvenv then you must do it yourself. You can reuse the file you downloaded earlier and just run it after you activate your new sandbox.



  • Examples updated with Python 3.3.5.


  • The Python versions used in the examples have been updated to 2.7.6 and 3.3.4.
  • The list of library prerequisites has been extended so that more features are compiled into Python.
  • New parameters for compiling Python with a shared library and for enabling Unicode UTF-32 support in Python 2.7 and Python 3.2 have been added.
  • Instructions for installing and using setuptools, pip, virtualenv and pyvenv have been added/updated.

Author: Daniel Eriksson

Athletic computer nerd from Sweden.

311 thoughts on “How to install Python 2.7 and Python 3.3 on CentOS 6”

    1. In order to compile Python you must first install the development tools and a few extra libs. The extra libs are not strictly needed to compile Python but without them your new Python interpreter will be quite useless

      sudo yum groupinstall “Development tools”

      sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

      Here are the commands to download, compile and install Python

      cd /usr/local/src
      sudo wget –no-check-certificate
      sudo tar xf Python-3.2.2.tar.xz
      cd Python-3.2.2
      sudo ./configure –prefix=/usr/local –enable-shared LDFLAGS=”-Wl,-rpath /usr/local/lib”
      sudo make && sudo make altinstall

      After running the commands above your newly installed Python interpreter will be available as /usr/local/bin/python3.2


      Download and install Setuptools + pip

      cd /usr/local/src
      sudo wget
      sudo /usr/local/bin/python3.2
      sudo /usr/local/bin/easy_install-3.2 pip

      Create your isolated Python 3.2 environment

      sudo /usr/local/bin/pip3.2 install virtualenv
      sudo /usr/local/bin/virtualenv /usr/local/virtenv3.2
      cd /usr/local/virtenv3.2
      source bin/activate
      python –version # (To check version)

    1. Are you sure you installed your new python version using the command “make altinstall”. If you just used “make install” then you have replaced the system version (/usr/bin/python).

      I think you can fix your problem simply by copying or linking /usr/bin/python2.6 to /usr/bin/python

      1. Ran into the same issue when trying, of all things, to update bash against the Bourne shell vulnerability. It took me about 12 hours to figure out that the system python was using the wrong libraries (for Fedora 19, the system python is at 2.7.5, and every time I ran python or did a python -V I got the wrong version).

        I ended up commenting out the reference to /usr/local/lib in, and everything was good.


        1. I can confirm this in Scientific Linux 6.4 as well. Took me more than 12 hours to figure out the problem though as I had installed new versions of Python and gcc. Removed /usr/local/lib from /etc/, ran ldconfig, and my system is back to normal now.

          1. Agreed. Adding python to ldconfig is a bad idea, that will normally manifest itself later on. Rather than removing /usr/local/lib, I would either put python in a different prefix (/usr/local/python for example) or replace /usr/local/lib with more explicit /usr/local/lib/ in the ldconf. After all, you’re probably going to need access to some libraries in /usr/local…

        2. Thanks for this comment. It helped me figure out why yum wasn’t working after I compiled Python 2.7.8 with /usr/local/lib in on a Red Hat 7.2 system whose system-wide default is Python 2.7.5. (I had executed sudo ./configure followed by sudo make. Hadn’t got to the sudo make altinstall step).

          However, if I try the other option
          $sudo ./configure –prefix=/usr/local/python –enable-unicode=ucs4 –enable-shared LDFLAGS=”-W1,-rpath /usr/local/python/lib” I encounter the error:

          configure: error: C compiler cannot create executables
          See `config.log’ for more details

          config.log contains the error message:
          gcc: error: unrecognized command line option ‘-W1,-rpath’

          How do I work around/fix this issue?

          1. My mistake – I had a typo in LDFLAGS. It should be -Wl and not -W1 (lower case L instead of digit 1). It worked fine with the correction.

  1. beautiful. worked perfect. Thanks for publishing. got me out of zlib error hell for a parallel python 2.7 install.

  2. Very nice, but how about throwing in a # yum install readline-devel? Makes the python interpreter easier to work with later (not to mention ipython).

    1. Thanks Erik, after installing readline-devel, config detects the readline libs automatically, and compile in the support by default… the command line is way better!

  3. I see failure when installing Tkinter using “easy_install-2.7 Tkinter”. How can I make it work?

    error: Could not find suitable distribution for Requirement.parse(‘Tkinter’)

    I needed another module ‘pexpect’ and “easy_install-2.7 pexpect” worked fine.

    1. Issue fixed: After ‘yum install tk-devel’ and then reinstall python “make && make altinstall” I was able to import Tkinter properly. Didnt have to install Tkinter explicitly using “easy_install-2.7 Tkinter”

      1. Thanks Sanjay! That fixed a persistent problem that I had. I’m so glad you took the trouble to post. I had tkinter working in the (default) Python2.6, so I knew that all the necessary .so files were installed, but I forgot/didn’t realize that the tk-devel files would be necessary during the compilation of Python2.7.

  4. after following all above steps, it istalled python 2.7(i checked directory where it install, its ok) but when i check python -V. it show python 2.6.6 instead of python 2.7. please help me how to change default python 2.6 to 2.7.

    1. You do NOT want to change default python version because that breaks some system services (like yum for example). You have two options:

      1. Always use “python2.7” instead of “python” when you start python scripts.
      2. Set up a virtualenv with python 2.7 and run everything from inside that virtualenv.

      1. i got this error “-bash: python2.7: command not found” after typing python2.7 install on your instruction in Download and install Distribute for Python 2.7, how can i overcome this wall? thanks in advance

  5. Thank you for doing this! I am having one problem…When I run:
    python2.7 install

    I get:
    bash: python2.7: command not found

  6. I get this error after I attempt to run Python for the first time:

    /usr/local/python2.7/bin/python: error while loading shared libraries: cannot open shared object file: No such file or directory

        1. Hi had a similar problem to install mod_wsgi – need to enable-shared and now can’t find libpython2.7

          Unfortunately your blog article seems down. Can you bring it back up?

          Many thanks

    1. If you typed


      when you installed, you may be getting this error because you forgot to run


      Just running that command fixed it for me

  7. You made this process so easy, thanks for the detailed steps! CentOS is too “stable” to be upgraded…. Only got python24 on my server.

  8. Thanks for the tutorial. How come there aren’t any easily obtainable RPMs for this kind of thing? It’s baffling to me that EPEL has PyPy 1.9 but no CPython 2.7.

    1. The best way is to run your Django app from inside a virtualenv. Look at the last steps in the article above for info on how to properly install virtualenv.

  9. Thanks very much. It all worked until I saw this:
    Python build finished, but the necessary bits to build these modules were not found:
    bsddb185 dl gdbm
    imageop sunaudiodev
    To find the necessary bits, look in in detect_modules() for the module’s name.

    running build_scripts
    creating build/scripts-2.7
    copying and adjusting /disk2/software/Python-2.7.3/Tools/scripts/pydoc -> build/scripts-2.7
    copying and adjusting /disk2/software/Python-2.7.3/Tools/scripts/idle -> build/scripts-2.7
    copying and adjusting /disk2/software/Python-2.7.3/Tools/scripts/2to3 -> build/scripts-2.7
    copying and adjusting /disk2/software/Python-2.7.3/Lib/ -> build/scripts-2.7
    changing mode of build/scripts-2.7/pydoc from 644 to 755
    changing mode of build/scripts-2.7/idle from 644 to 755
    changing mode of build/scripts-2.7/2to3 from 644 to 755
    changing mode of build/scripts-2.7/ from 644 to 755
    /usr/bin/install -c -m 644 ./Tools/gdb/
    make: stat: Modules/ Permission denied
    make: *** No rule to make target Modules/', needed by Makefile’. Stop.
    There is nothing at all in my /usr/local/bin.

    Any suggestions?

    1. I’m far from an expert, but the Python readme contains this:
      Unix platforms: If your vendor still ships (and you still use) Berkeley DB
      1.85 you will need to edit Modules/Setup to build the bsddb185
      module and add a line to which makes it the
      default. In Modules/Setup a line like

      bsddb185 bsddbmodule.c

      should work. (You may need to add -I, -L or -l flags to direct the
      compiler and linker to your include files and libraries.)

      XXX I think this next bit is out of date:

      64-bit platforms: The modules audioop, and imageop don’t work.
      The script disables them on 64-bit installations.
      Don’t try to enable them in the Modules/Setup file. They
      contain code that is quite wordsize sensitive. (If you have a
      fix, let us know!)

      That all suggests to me that you can edit the configuration, but there may be more information lower down in the readme. For example, I had to dig to find –enable-shared, which I needed.

      1. Thanks for replying. I think I’ve got it now. It turned out to be a file protection problem. I’ve been trying to install using “sudo make && make altinstall” but apparently sudo doesn’t let me cd to directories that I don’t have rights too. So at first I started changing all the directories I needed in the source tree to 755. I still ran into a problem installing files into /usr/local/bin – I didn’t want to change the protection there. Fortunately, I could just do “sudo su” and do the install as root.

          1. Something that can be easy forgotten due to the first ‘sudo’ and ‘&&’.

        1. First I want to thank Daniel Eriksson and all others who have posted their experience and solutions. I don’t have any knowledge about building packages at this level on *nix…

          I’ve simply been following instructions listed on this page to install python-2.7.9, things went so well I’ll try 3.4.2 also…

          I encountered similar error to Dave.

          I too was using ” sudo ” to run commands to perform installs.

          After reading Dave’s post above I went back and ran everything as ” root ” ( su root ),

          ./configure –prefix=/usr/local –enable-unicode=ucs4 –enable-shared

          make && make altinstall

          ls -l /usr/local/bin/py*

          -rwxr-xr-x 1 root root 84 Dec 23 17:16 /usr/local/bin/pydoc*
          -rwxr-xr-x 1 root root 9760 Dec 23 17:47 /usr/local/bin/python2.7*
          -rwxr-xr-x 1 root root 1687 Dec 23 17:47 /usr/local/bin/python2.7-config*

          Thanks Dave, for posting complete message which I searched for and found. My issue appears to be resolved after running as ” root ” and not ” sudo ”

          Python build finished, but the necessary bits to build these modules were not found:
          bsddb185 dl imageop
          To find the necessary bits, look in in detect_modules() for the module’s name.

          running build_scripts
          creating build/scripts-2.7
          copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/pydoc -> build/scripts-2.7
          copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/idle -> build/scripts-2.7
          copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/2to3 -> build/scripts-2.7
          copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Lib/ -> build/scripts-2.7
          changing mode of build/scripts-2.7/pydoc from 644 to 755
          changing mode of build/scripts-2.7/idle from 644 to 755
          changing mode of build/scripts-2.7/2to3 from 644 to 755
          changing mode of build/scripts-2.7/ from 644 to 755
          /usr/bin/install -c -m 644 ./Tools/gdb/
          /usr/bin/install -c python /usr/local/bin/python2.7
          /usr/bin/install: cannot create regular file `/usr/local/bin/python2.7′: Permission denied
          make: *** [altbininstall] Error 1

  10. I managed to install python 2.7.3 without breaking yum.

    How to make a specific user to use python 2.7.3 as virtual env ?

    1. Each virtualenv has its own Python version that is set when the virtualenv is first created. It is up to the user to decide what Python version he/she wants in each virtualenv.

  11. Thanks a bunch. Was having a hard time getting python to install with many other resource I found on google. 10*

  12. Thanks for the tutorial. I did everything you said, so if I understand correctly, now I have to install
    1) python 2.7 once again
    2) Will this virtualenv become default or how do I control it ?

    I dont know much about python and vertualenv, hence the silly questions.

    1. If you followed the tutorial you already have everything you need. When you create a new virtualenv you will automatically get a copy of the proper version of python inside that folder structure.

      A virtualenv is never “default”, you have to manually activate it. Once activated your default python interpreter will change from the system default to the one in that particular virtualenv.

      You can have as many virtualenv as you like on a machine, and each virtualenv can have a different default python interpreter, and different installed packages.

      This is really useful when you develop multiple applications, each with different requirements. I do Django development myself and it is really useful to have one virtualenv for each project because one website might run Django 1.4, another might run 1.2 and yet another one might run 1.5 beta. I do most of my development in Eclipse with the pydev plugin, and that plugin knows about virtualenv so I just configure one interpreter for each project and point it at the python executable inside that particular virtualenv.

  13. Very useful post, you can update some version numbers that also worked for me: Centos 6.3 and distribute 0.6.35

  14. I have now updated the tutorial with additional information provided here in the comments, plus updated versions, plus more information about virtualenv. Enjoy!

    1. The system default Python interpreter does not change, that is the whole point of this tutorial. To start your new Python interpreter you must issue the command /usr/local/bin/python2.7 (or simply python2.7 if /usr/local/bin is in your PATH which it usually is).

  15. Hi there!
    I have problem while running “make && make altinstall”. It overlap and non-stop, i mean the installation never finished. It showing:

    By default, distutils will build C++ extension modules with “g++”.
    If this is not intended, then set CXX on the configure command line.

    And then restart the installation process.

    1. Unfortunately I don’t know what could be causing that problem. Maybe you have installed something that messes around with your C/C++ toolchain. My only advice is to google the error message and see how others have solved it.

  16. Dear Colleagues,

    I tried to install Python 2.7.3 and Python 3.3.0 following the method published in this blog.
    My yum is now broken and after I requested the centos forum, I was advised to uninstall these 2 versions of python. How do I uninstall them, is there a command to do this?

    With best regards,

    1. Are you sure you followed the instructions? Especially the part where you use ALTINSTALL instead of INSTALL? I doubt you did, because if you used ALTINSTALL then the system version of Python would still be 2.6.6.

      What is the output of the following commands:
      # python –version
      # /usr/bin/python –version

      The Python makefile does not provide an uninstall target so you will have to remove the files manually if you want that.

      1. I did the same thing.. I thought I needed 2.7.3 along with 3.3 so I installed both.. I did do it with altinstall though.. so my yum works fine…

        How do I uninstall 3.3? I see you wrote just remove the files.. but can you be more specific as there are a ton of files?

  17. Dear Daniel,

    Thank you for replying back. Please find the required information below.

    $ python -V
    Python 2.7

    $ yum
    -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

    Can we change the defauly version of python to the original 2.6.6?

    With best regards,

    1. Please check the version of /usr/bin/python.

      If it is 2.6.6 then your PATH is most likely in the wrong order (/usr/bin should be before /usr/local/bin).

      If it is 2.7.3 then you didn’t follow the steps in this guide. You can still salvage the situation by doing this:

      rm /usr/bin/python
      ln -s /usr/bin/python2.6 /usr/bin/python

  18. Dear Daniel,

    You are right, I may have done a lot of more than what the guide says (I have a 64 bit system). Please kindly help me resolve this error, as most of my work is pending because I am not able to use yum. We could connect via webex/ teamviewer, please let me know when you are free and I will send you my teamviewer login details.
    I have tried out your suggestions, but the error with yum remains. Please find the below log-

    $rm /usr/bin/python
    rm: remove symbolic link `/usr/bin/python’? y
    $ln -s /usr/bin/python2.6 /usr/bin/python
    -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
    $python -V
    Python 2.7

    Thanking you and with best regards,

    1. Verify that /usr/bin/python2.6 really is version 2.6. If it is then you have another binary called python somewhere else in your filesystem, in a location that is searched before /usr/bin. Check the order of your PATH variable.

  19. Thanks Daniel for the great tutorial. I’ve installed PyCrypto, and it fails with the following:

    Running pycrypto-2.6/ -q bdist_egg –dist-dir /tmp/easy_install-wQetbc/pycrypto-2.6/egg-dist-tmp-FPHtu0
    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    zip_safe flag not set; analyzing archive contents…

    Then, I ran yum install mpir, and I got:
    Package mpir-1.3.1-4.el6.x86_64 already installed and latest version .
    Similarly, it said gmp was installed and latest.

    I’ve been told I need python2.7.3-devel to get PyCrypto to build. I can get it from an RPM I found but I don’t think it’s a great idea (I have to symlink all kinds of things everywhere and then install the RPM — maybe not great.)

    Any idea how I can solve this? Also, if I want to remove Python 2.7.3: Any specific instructions?

    Thanks again!

    1. Not sure I can help you with PyCrypto, at least not right now, but I can tell you that you already have what is included in the devel package (libs and headers).

      Removing Python is pretty easy, all the files you need to delete are located under /usr/local and fairly easy to spot. This should get you going:

      /usr/local/include/python2.7 (dir)
      /usr/local/lib/python2.7 (dir)

      There are a few more executables under /usr/local/bin that you can remove also (pydoc, idle, 2to3, …). List the dir in chronological order to see what other (if any) files were installed there at the same time as python2.7.

  20. Thanks! Worked perfectly on CentOS 6.4. I have 2.6.6, 2.7.3 and 3.3 all living in peaceful harmony.

  21. Pingback: Living Cosmos
  22. Hi Daniel,

    This is by far the best tutorial I have found for installing python 3.3 on Centos. After running into some permission errors, I successfully ran the make && make altinstall. The folder created is /usr/local/bin/python3.3m as opposed to /usr/local/bin/python3.3.

    When I try to run the command python3.3 install, I receive the error: “-bash: python3.3: command not found”. Any ideas on how to fix this?

  23. Daniel, thanks for the tutorial. This worked like a charm on Cent OS 5.7, which ships with Python 2.4.

    FYI, the newest versions are 2.7.4 and 3.3.1, released yesterday and today, respectively. I installed 2.7.4 no problem by just replacing the release version number in your instructions. (Didn’t try 3.3.1.)

    It’s great to have these straight-forward instructions for those of us who know enough about linux to easily understand & follow your tutorial, but don’t perform these actions regularly enough for them to be intuitive. (I would never have thought to install the development tools first, for example.) Thank you very much.

  24. Hi Daniel,
    I am new to Linux, I am following your steps to install python3.3 on cent0s 6, all the steps works until when I get to “make && make altinstall”.
    Ithrows the following error: make: *** No targets specified and no makefile found. Stop.
    it seems that, I am not getting something right. Could you please help. Many thanks

      1. I haven’t done 3.3, but this sound like you’re running the command in the wrong directory. Are you in the directory containing the makefile (probably actually named Makefile) ?

        1. Thanks for the reply Dave, yes I was in the Makefile directory. All the steps from Daniel worked until when I go to “make && make altinstall” Cheers.

          1. Most strange. Does “make –file=Makefile” behave any better ? Or “make –file=./Makefile” ? If not, I’d suggest showing us the output of “pwd; ls -l; alias make ; env |grep -i make” (all just grasping at straws.)

  25. Did anyone answer the question about setting the PYTHONPATH in the virtual environment or is that not necessary?

  26. Just a philosophical question: what’s the point of the centos package management, if you have to install packages manually?

    1. In this case, it’s because the CentOS repositories do not have Python 2.7 and 3 in them and the versions that they do contain are rather obsolete.

  27. hello, i’m trying to install anki 2.0.3 on my cent 6.x box, followed instructions, but anki rpm still says that it needs 2.7 to install? halp?

  28. Following the instructions to build 2.7.4 on CentOS 6.4 I get

    ‘WARNING: old charecter set or encoding…’ message and a garbaged screen only starting /usr/local/bin/python2.7 but not Python

  29. Thanks a lott, really helpful
    Fix: I think you’re missing a j in
    tar xf Python-2.7.3.tar.bz2
    should be
    tar jxf Python-2.7.3.tar.bz2

  30. Worked perfectly with 2.7.4 and 3.3.1 on Fedora 18. I prefer to have my installations more self-contained, so I added the –prefix and –exec-prefix options to the configure command line.

  31. Thank you all very much guys! (Dave T and Daniel). I installed GCC and after that, the “make && make altinstall” ran perfectly. Python is now upgraded to 3.3. I have been away, hence the late response, pardon. Much appreciations for your expert advice.

  32. Very good instructions. It got me half of the way there, but… Do you happen to know how to get the rest of the package (2.7)? The whole point of installing 2.7 in my case was one function: to run a Cython conversion, which requires the -devel package/headers. The CentOS (version 2.6) -devel files were installed with 2.6 but could never be found found by Cython, and apparently the 2.7 from does not include -devel files at all?? I have been all over’s site, but if the -devel package is there, I cannot find it. Is it available anywhere else? Obviously CentOS won’t have it, since they did not have version 2.7.

  33. This was clear, concise, and accurate. Thank you for taking the time to put this together– I greatly appreciate it! This saved me hours putting together the steps on my own.

  34. The above instructions worked great. I am tyring to install mininet from rpm and it is complaining that it requires /usr/bin/python2.7. /usr/bin/python is 2.6.6 and /usr/bin/python2.7 is 2.7.5. Any thoughts on how to get around this dependency on /usr/bin/python being version 2.6?

  35. Hello, thanks for the post, worked fine.

    In you guide you recommend to install “Distribute” but now on their website it’s written that it’s a deprecated fork of “Setuptools”. Maybe a small upgrade to your guide?


        1. Ooops, I had no idea this was taking place. I wonder if Setuptools 0.7.2 is “production ready” yet? Time to go run some tests. Thanks a lot for the heads-up!

  36. Worked perfectly first time on CentOS 6.4 (though I used the updated versions of each).
    Much appreciated!

  37. Great post! I also added the following dependencies: gdbm-devel and db4-devel
    This allows for gdbm, dbm, and _bsddb to build.
    My final unsupported modules (after running make) for python 2.7 on x64 were:
    bsddb185 dl imageop sunaudiodev
    All of which are obsolete.
    I also second the previous poster about installing setuptools over distribute.

  38. Thanks for this guide. However, I do not have root privileges on this computer. I wanted to install python 2.7 since all the codes I have written are optimized for 2.7. I also want this to be the default version and wanted to know if this was possible?

  39. Daniel, Thanks for putting this up! However I’m getting:
    /usr/bin/install: cannot create regular file `/usr/local/bin/python2.7′: Permission denied
    When running “make && make altinstall” even if I run sudo with the command. I’d appreciate any help you could give!

    1. This sounds like the issue Dave M reported on 2012/12/22, above.

      If /usr/local/bin is mounted from a remote machine, that could cause problems, too; remote root write access is often disabled on exported filesystems. Does /usr/local/bin/python2.7 already exist ? If so, who owns it, and what are the permissions ? If not, then same questions for /usr/local/bin, then /usr/local.

      As ever, I’m just grasping at straws.

      1. I appreciate it Dave! I actually figured it out, but forgot to post back here. For whatever reason running “sudo make && make altinstall” with my sudo user didn’t work. Even if I changed the owner of the bin/python2.7 Yet then I tried running “sudo bash” then “make && make altinstall” and it work perfectly!

        1. You should have instead done this:
          make && sudo make altinstall
          The way you did it, sudo only applies to the first make – which doesn’t even need to be done by root. Only “make altinstall” needs to run as root, because that is when files are created in /usr directories.

      2. Worked for me using “sudo make altinstall”. If that doesnt work try “chmod 744 /usr/local/bin” (depending on your security situation). Note that if you use sudo then python2.7 will only be available to the root user.

  40. Hello,

    Thanks a lot by the tutorial…

    I need to install python-devel now for version 2.7.

    I tried “easy_install-2.7 python-devel” and got the following:

    Couldn’t find index page for ‘python-devel’ (maybe misspelled?)
    Scanning index of all packages (this may take a while)
    No local packages or download links found for python-devel
    error: Could not find suitable distribution for Requirement.parse(‘python-devel’)

    Any ideas?



  41. Hi,

    I did exactly as you mentioned but how do I install python abi for 2.7 can you let me know. One of the packages I am trying to install depends on python abi 2.7 !!

  42. Hi friends!

    # virtualenv-2.7 –distribute someproject

    Could anybody tell me one example of ‘someproject’ ?

    The domain folder root? Is this correct?

    # virtualenv-2.7 –distribute /var/www/vhosts/


    1. “someproject” is the aliase you choose for your python. for example, you could use py273 for Python2.7.3 and the system will create a directory py273 under the ../distribute-0.7.3

  43. Hello,

    I have installed Python 2.7 by on centos 5 from source code. Python 2.4 is already there in centos 5. Could you please help me to uninstall Python 2.7 so that I can reinstall it with yum.

  44. Any advice on installing scipy/numpy/matplotlib this way? I’m using centos 6 and was able to get python2.7 and distribute installed using the great instructions above. But “easy_install2.7 scipy” fails (even after numpy is installed).

    1. Hi python27,
      I have the same issues as your. Did you manage to get rid of it ?

  45. This is one of the clearest how-to articles I have encountered in years! You completely covered the steps required from A-Z. I didn’t know how much was missing from other articles until I read this. Thank you so much.

  46. Hi I followed the steps to install python2.7 but still I run into following errors:

    I guess it might be because ssl is not getting configured for my python2.7 install, am not able to get past it
    Can somebody plz help.

  47. Hi, thanks for these great and clear instructions! I only had one problem when I got to the portion of installing Distribute. The setup for Distribute would not work unless I added the option “-with-zlib=/usr/include” to the configure script line. So, like this:

    ./configure –prefix=/usr/local -with-zlib=/usr/include

    if it helps, I was on Centos 6.4, trying to install Python 2.7.5 and distribute 0.6.49.

  48. “someproject” is the aliase you choose for your python. for example, you could use py273 for Python2.7.3 and the system will create a directory py273 under the ../distribute-0.7.3

  49. Very awesome work Daniel. The extra tips on installing distribute and virtualenv were well worth coming here, thanks a lot.

    Also, I don’t know if anyone else pointed it out, but it is unfortunate that CentOS 6 repos don’t have a python2.7 rpm on them. I will see if they have a bug about this already, and file one if they don’t.

  50. When build your python, be sure to put

    Otherwise it will be built in UCS2 model, leading “undefined symbol: PyUnicodeUCS2_GetSize” errors in package matplotlib. Thanks.

    1. Add
      to the request, either just after the wget or at the end of the line.

  51. after reading so many articals about easy_install,pip and virtualenv,this one is most usefull and clearly.Thank you very much~

  52. To install and get working the actual Python version 3.3.2 @ up-to-date CentOS 6.4,
    you need to modify the step “Download and install Python 3.3.x”
    by adding –with-ssl:
    ./configure –with-ssl –prefix=/usr/local
    Otherwise you end up with numerous ssl related errors and stuff not working.
    (e.g. :
    /usr/local/bin/easy_install-3.3 virtualenv
    Searching for virtualenv
    Download error on unknown url type: https — Some packages may not be found!

    # pip -V

    ImportError: No module named ‘_ssl’

  53. thank you first.
    And i have another question,since when we use virtualenv,we always use it like this way:/usr/local/bin/virtualenv-XXXX or /usr/local/bin/virtualenv-yyyy rather than simply use /usr/local/bin/virtualenv,why not remove or rename /usr/local/virtualenv?
    this file may bring some confusion because of the version information.

  54. Hello,
    where does distribute download? in /usr/local/?
    After install distribute, Can I delete distribute folder?


  55. Hi Daniel,
    I have got an HTTPSHandler error while installing packages using pip as with the following stacktrack,
    on ubuntu10.04 with python2.7

    ———————————desktop:~$ pip install Django==1.3
    Traceback (most recent call last):
    File “/home/gaurav/.genv/bin/pip”, line 9, in
    load_entry_point(‘pip==1.4.1’, ‘console_scripts’, ‘pip’)()
    . from urllib2 import (Request, urlopen, URLError, HTTPError,
    ImportError: cannot import name HTTPSHandler

    Help to come out from this error, will be thankful to you 🙂


    libpcap: module provides a user-level network packet capture information and statistics.
    libncurses: is a API programming library that enables programmers to provide text-based interfaces in a terminal.
    gcc: GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages.

    Install libpcap, libnurses, gcc via yum
    yum -y install libpcap libpcap-devel ncurses ncurses-devel gcc

    Download and Install iftop
    make install

  57. Excellent and very helpful article, thank you!

    BTW, tried to follow the procedure Today on CentOS 6.4 64bi and encountered error “… OSError: Command /home/swamydkv/py_virenv/test/bin/python3 -c “import sys, pip; pip…ll\”] + sys.argv[1:])” setuptools pip failed with error code 1″ described at following URL:

    It looks we have a bug in current version of setuptools, so fix was to downgrade virtualenv to 1.10.1 using following command:
    easy_install “virtualenv<1.11"

    Hope this info will be helpful if someone runs in the same issue I had Today J.

  58. Thanks for the post… and for the update to the recently-released python 3.3.4. I have used this page as reference a few times in the past and today, while showing it to a friend that wanted to upgrade python on an older server, I saw you had the updated instructions for 3.3.4, which got released just 3 days ago.

  59. If this is only for development, isn’t it better to avoid system wide installation by using –prefix=$HOME/.fakeroot/usr?

    1. I think that is a personal preference thing. If I have root access I usually install things like this system-wide even if it is only used for development. One reason to do this is that I want to keep my development/staging environment as close as possible to the deployment environment.

      When I don’t have root access I usually install in $HOME/Python-x.y.z to keep it fully separated from other user-installed apps. I don’t even add that bin dir to the path because I just need it once when I set up a new isolated environment with virtualenv or pyvenv.

  60. Hi Daniel,

    Many, many thanks for what has to be the best tutorial on the web for installing Python 2.7 and 3.3 on CentOS 6. I tried it and it worked fine.

    I don’t know if you’ve run into this, however, and if you did I’d appreciate any insight you have to it. After installing Python 3.3 according to your instructions, then doing pip install’s of the following within the virtualenv of my33project:


    I get the following error when I run “ipython3 –pylab”:

    [TerminalIPythonApp] WARNING | GUI event loop or pylab initialization failed

    Here are the errors pointed to with the warning:

    TclError Traceback (most recent call last)
    /usr/local/lib/python3.3/site-packages/IPython/core/ in (key)
    221 shell =
    222 if self.pylab:
    –> 223 enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
    224 key = self.pylab
    225 elif self.matplotlib:

    /usr/local/lib/python3.3/site-packages/IPython/core/ in enable_pylab(self, gui, import_all, welcome_message)
    2918 from IPython.core.pylabtools import import_pylab
    -> 2920 gui, backend = self.enable_matplotlib(gui)
    2922 # We want to prevent the loading of pylab to pollute the user’s

    /usr/local/lib/python3.3/site-packages/IPython/core/ in enable_matplotlib(self, gui)
    2884 # Now we must activate the gui pylab wants to use, and fix %run to take
    2885 # plot updates into account
    -> 2886 self.enable_gui(gui)
    2887 self.magics_manager.registry[‘ExecutionMagics’].default_runner = \
    2888 pt.mpl_runner(self.safe_execfile)

    /usr/local/lib/python3.3/site-packages/IPython/terminal/ in enable_gui(gui, app)
    306 from IPython.lib.inputhook import enable_gui as real_enable_gui
    307 try:
    –> 308 return real_enable_gui(gui, app)
    309 except ValueError as e:
    310 raise UsageError(“%s” % e)

    /usr/local/lib/python3.3/site-packages/IPython/lib/ in enable_gui(gui, app)
    526 e = “Invalid GUI request %r, valid ones are:%s” % (gui, list(guis.keys()))
    527 raise ValueError(e)
    –> 528 return gui_hook(app)

    /usr/local/lib/python3.3/site-packages/IPython/lib/ in enable_tk(self, app)
    322 if app is None:
    323 import tkinter
    –> 324 app = tkinter.Tk()
    325 app.withdraw()
    326 self._apps[GUI_TK] = app

    /usr/local/lib/python3.3/tkinter/ in __init__(self, screenName, baseName, className, useTk, sync, use)
    1798 baseName = baseName + ext
    1799 interactive = 0
    -> 1800 = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
    1801 if useTk:
    1802 self._loadtk()

    TclError: no display name and no $DISPLAY environment variable

    Would you know how to fix this?

    1. These look like standard messages from an X-enabled application unable to open the display. I don’t use ipython, but I believe it has a command-line option to run in the terminal.
      If you ssh’d to the machine where you’re running ipython, you may have forgotten to use the ssh option -X or -Y.

      1. Hi Dave, and thanks for the reply.

        X11 Forwarding is already enabled through the sshd_config file. I don’t see what starting the shell session with the -X or -Y option would do above that.

  61. Another blind stab: it looks like ipython3 is doing its work in subprocesses. Perhaps those are running login shells which unset or otherwise disturb the DISPLAY setting ? But clearly Daniel’s question is the key.
    Can xclock, xlogo, xload, or any other X application run ?

  62. before i could successfully do:

    i had to:
    yum install zlib-devel

    then redo the python install:
    make&&make altinstall

    then it works

  63. Hi,

    In Python 3.3, can you add installation of the xz-devel package? It is needed for lzma module

  64. If you’re getting permission errors when running easy_install and pip, but sudo’ing gives you ‘command not found’ errors, the path for the superuser is different from yours. Wrap the command in a $(which commandname) before passing into sudo so it looks on the absolute path:

    sudo $(which pip2.7) install virtualenv

  65. what happens if python is upgraded to 2.7 and 2.7 has to be run the same time as yum. That is:

    /usr/bin/yum -d 0 -e 0 -y install openstack-keystone

    This command also checks that the package openstack-keystone needs python 2.7 libraries
    and throws error if they are not found, but on the same time yum needs python2.6.x

    Can these 2 demands live together ?

    1. First of all you don’t actually upgrade Python by following the instructions in this guide, you merely install a new version side-by-side. I have no idea what happens if Python 2.7 is called from a script running under Python 2.6. If PYTHONPATH is mangled then all sorts of (not so) funny things might happen. Why not do a quick test in a VM (or on a VPS that charges by the minute or hour)? I don’t know enough about OpenStack to verify if Keystone works if I could get it to install, so I would just be wasting my time doing it.

  66. Dear Daniel,
    Why do i get this error when trying to execute this command

    File “/usr/local/lib/python3.4/”, line 614, in _get_decompressor
    return zlib.decompressobj(-15)
    AttributeError: ‘NoneType’ object has no attribute ‘decompressobj’

    Best regards

      1. Hi, I have the same problem. I installed zlib-devel AFTER building python. How can I proceed now with the pip installation?

  67. Pingback: Quora
  68. hi all, I am trying to install PySide on Python3.3 (CentOS) – have tried either pip install PySide or easyinstall-3.3 PySide but both fails with error message – Failed to find cmake. Please specify the path to cmake with –cmake parameter.

    if i used yum, install seems to work but Python3.3 can’t detect it.

    any advice? thank you!

  69. Ok i gotten further. installed cmake via yum and that got me further.
    however, now pyside fails install with error compiling shiboken – make: *** [all] Error 2

    still googling trying to figure out whats wrong

  70. For 64 bit systems, add the line:


    to /etc/ to make it look like the following.


    This solves the potential error of:

    problem loading shared libraries: cannot open shared object file: No such file or directory

  71. Installed correctly.

    When I run Python will work —> /usr/local/bin/python2.7

    ” Python 2.7.6 (default, Jun 6 2014, 11:02:54)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.

    More so when I run, does not work -> /usr/bin/python2.7

    ” -bash: /usr/bin/python2.7: No such file or directory ”

    How do I run the 2 commands? For I have a server that works.

    Help me please.

  72. I had a hard time interpreting what you meant about whether or not to install unicode support. I would like to recommend that you change:

    “Unless you have very specific reasons you should configure Python 3.2 and earlier to enable UTF-32 support.”


    “Unless you have very specific reasons, you should configure Python 3.2 and earlier to enable UTF-32 support.”

    I think the comma will make a mental pause that can help separate the if/then structure.

  73. A straightforward review of that process (for Python 3.2.2!)…


    * Install Python 3.2.2 (CentOS 6.5):



    – In order to compile Python you must first install the development tools and a few
    extra libs. The extra libs are not strictly needed to compile Python but without
    them your new Python interpreter will be quite useless

    yum groupinstall “Development tools”
    yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel


    – Here are the commands to download, compile and install Python

    wget –no-check-certificate
    tar xf Python-3.2.2.tar.xz
    cd Python-3.2.2
    ./configure –prefix=/usr/local –enable-shared LDFLAGS=”-Wl,-rpath /usr/local/lib”
    make && sudo make altinstall


    – After running the commands above your newly installed Python interpreter will
    be available as /usr/local/bin/python3.2



    – Download and install Setuptools + pip

    cd ~/Downloads
    sudo /usr/local/bin/python3.2
    sudo /usr/local/bin/easy_install-3.2 pip


    – Create your isolated Python 3.2 environment

    sudo /usr/local/bin/pip3.2 install virtualenv
    sudo /usr/local/bin/virtualenv ~/virtenv3.2 (maybe /usr/local/bin/virtualenv-3.2)
    cd ~/virtenv3.2
    source bin/activate
    python –version (To check version)


    Many thanks Daniel Eriksson! You awesome!


    GrooVim – Vi IMproved’n’GrooVIed!

  74. I could not use matplotlib after I install python 2.7. All the other packages work well. And matplotlib works well with python 2.6 (the system default one). When I import gtk or import pygtk, it shows I don’t have those modules. Have any solution?

  75. now forces https, and that wget command no longer works as-is:

    $ wget
    –2014-07-03 19:10:25–
    Connecting to||:80… connected.
    HTTP request sent, awaiting response… 301 Moved Permanently
    Location: [following]
    –2014-07-03 19:10:30–
    Connecting to||:443… connected.
    ERROR: certificate common name “*” doesn’t match requested host name “”.
    To connect to insecurely, use ‘–no-check-certificate’.

    Suggest adding “–no-check-certificate” to the instructions.

  76. Instead of adding a line to /etc/, I think it’s a better idea to create a separate .conf file into the /etc/
    That would make possible to do it easier (with just one command), it can be done several times without worrying about duplicate lines and it’s more clean. For instance:
    echo “/usr/local/lib” > /etc/

    And it’s also easier to revert:
    rm /etc/

  77. Hi this looks like a perfect solution to my problem but for some reason when trying to extract either of the pre compiled downloads i get the following error :/

    root@pancakes [~]# tar xf Python-2.7.6.tar.xz
    tar: This does not look like a tar archive
    tar: Skipping to next header
    tar: Archive contains obsolescent base-64 headers
    tar: Read 6968 bytes from Python-2.7.6.tar.xz
    tar: Error exit delayed from previous errors

  78. Hello All,

    I’m new to python world and getting some error while installing python 2.7.6, please refer below for more details

    Error Log :-
    checking whether the C compiler works… no
    configure: error: in `/home/hadoop/hadoop/Python-3.3.5′:
    configure: error: C compiler cannot create executables


    After saw the above error I had install C compilar and try again, but the result is same

    command used for installation —> yum install compat-gcc-34-g77

    Version information
    hostname = localhost.localdomain
    uname -m = i686
    uname -r = 2.6.32-358.el6.i686
    uname -s = Linux
    uname -v = #1 SMP Thu Feb 21 21:50:49 UTC 2013
    /usr/bin/uname -p = unknown
    /bin/uname -X = unknown

    /bin/arch = i686
    /usr/bin/arch -k = unknown

    Please help me to solve this problem.

    Thanks & Regards,


  79. How many comments?? Thanks for this. I used this to help me install Python 2.7 on and AWS instance as the new S3 tools need 2.7 and yum needs 2.6.

  80. I am running into the following error while executing “python2.7”

    Traceback (most recent call last):
    File “”, line 332, in
    File “”, line 327, in main
    File “”, line 287, in download_setuptools
    downloader(url, saveto)
    File “”, line 224, in download_file_wget
    _clean_check(cmd, target)
    File “”, line 169, in _clean_check
    File “/usr/local/lib/python2.7/”, line 504, in check_call
    raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command ‘[‘wget’, ‘’, ‘–quiet’, ‘–output-document’, ‘/root/’]’ returned non-zero exit status 1

    Any suggestions ?

  81. I followed your step to do a new python install in centos7 but ran into trouble at group install step and make step.

    at the group install step:

    No such command: Development tools. Please use /bin/yum –help
    [chizzo@localhost ~]$ sudo yum groupinstall “Development Tools”
    Loaded plugins: fastestmirror, langpacks
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Loading mirror speeds from cached hostfile
    * base:
    * extras:
    * updates:
    Warning: Group development does not have any packages to install.
    Maybe run: yum groups mark install (see man yum)
    No packages in any requested group available to install or update

    I just moved on and ran the next command and it installed a bunch of stuff.
    But then at the make step:

    [chizzo@localhost Python-3.3.5]$ sudo make && make altinstall
    [sudo] password for chizzo:
    running build
    running build_ext
    running build_scripts
    copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/pydoc3 -> build/scripts-3.3
    copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/idle3 -> build/scripts-3.3
    copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/2to3 -> build/scripts-3.3
    copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/pyvenv -> build/scripts-3.3
    changing mode of build/scripts-3.3/pydoc3 from 644 to 755
    changing mode of build/scripts-3.3/idle3 from 644 to 755
    changing mode of build/scripts-3.3/2to3 from 644 to 755
    changing mode of build/scripts-3.3/pyvenv from 644 to 755
    renaming build/scripts-3.3/pydoc3 to build/scripts-3.3/pydoc3.3
    renaming build/scripts-3.3/idle3 to build/scripts-3.3/idle3.3
    renaming build/scripts-3.3/2to3 to build/scripts-3.3/2to3-3.3
    renaming build/scripts-3.3/pyvenv to build/scripts-3.3/pyvenv-3.3
    /usr/bin/install -c python /usr/local/bin/python3.3m
    /usr/bin/install: cannot create regular file ‘/usr/local/bin/python3.3m’: Permission denied
    make: *** [altbininstall] Error 1
    [chizzo@localhost Python-3.3.5]

    The contents of /usr/local/ do not show any install.
    not sure what to do other than google around…

    1. mc,

      Did you ever resolve issue you mentioned above.

      I would recommend running following as root instead of using sudo. That solved my issue…

      sudo su

      add ” /usr/local/lib ” to /etc/

      cat /etc/


      cd /home/chizzo/tmp/Python-3.3.5

      ./configure –prefix=/usr/local –enable-unicode=ucs4

      make && make altinstall

  82. To run pydoc with correct python version, I found this works:
    /usr/local/bin/python2.7 -m pydoc

    $ type pydoc
    pydoc is aliased to `python -m pydoc’

    So I guess could re-alias pydoc to use python2.7.

  83. Hi

    Great stuff man!

    I’m trying to run django in the virtualenv and that’s what I’m getting
    Traceback (most recent call last):
    File “”, line 8, in
    from import execute_from_command_line
    ImportError: No module named

    any thoughts?


  84. I followed instructions as listed. I choose second option for compiling Python as a shared library:

    added ” /usr/local/lib ” to /etc/

    cat /etc/

    sudo ldconfig
    cd ( to go to my home directory )

    sudo mkdir Downloads

    cd Downloads
    sudo wget
    sudo wget

    tar xf Python-2.7.9.tar.xz
    tar xf Python-3.4.2.tar.xz

    ls -ld Python*
    drwxr-xr-x 18 sgadmn sgadmn 4096 Dec 23 17:47 Python-2.7.9/
    -rw-rw-r– 1 sgadmn sgadmn 12164712 Dec 10 09:08 Python-2.7.9.tar.xz
    drwxr-xr-x 16 sgadmn sgadmn 4096 Dec 23 18:08 Python-3.4.2/
    -rw-rw-r– 1 sgadmn sgadmn 14223804 Oct 8 01:25 Python-3.4.2.tar.xz

    cd Python-2.7.9

    sudo ./configure –prefix=/usr/local –enable-unicode=ucs4

    sudo make && make altinstall

    cd ../Python-3.4.2

    sudo ./configure –prefix=/usr/local –enable-unicode=ucs4

    sudo make && make altinstall

    I got following error when running ” sudo make && make altinstall ”

    Python build finished, but the necessary bits to build these modules were not found:
    bsddb185 dl imageop
    To find the necessary bits, look in in detect_modules() for the module’s name.

    running build_scripts
    creating build/scripts-2.7
    copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/pydoc -> build/scripts-2.7
    copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/idle -> build/scripts-2.7
    copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/2to3 -> build/scripts-2.7
    copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Lib/ -> build/scripts-2.7
    changing mode of build/scripts-2.7/pydoc from 644 to 755
    changing mode of build/scripts-2.7/idle from 644 to 755
    changing mode of build/scripts-2.7/2to3 from 644 to 755
    changing mode of build/scripts-2.7/ from 644 to 755
    /usr/bin/install -c -m 644 ./Tools/gdb/
    /usr/bin/install -c python /usr/local/bin/python2.7
    /usr/bin/install: cannot create regular file `/usr/local/bin/python2.7′: Permission denied
    make: *** [altbininstall] Error 1

    So I went back and ran everything again as root:

    sudo su

    cd /home/my-homedir/Downloads/Python-2.7.9

    ./configure –prefix=/usr/local –enable-unicode=ucs4

    make && make altinstall

    cd /home/my-homedir/Downloads/Python-3.4.2

    ./configure –prefix=/usr/local –enable-unicode=ucs4

    make && make altinstall

    cd /usr/local/bin

    ls -ld py*
    -rwxr-xr-x 1 root root 84 Dec 23 17:16 pydoc*
    -rwxr-xr-x 1 root root 84 Dec 23 18:09 pydoc3.4*
    -rwxr-xr-x 1 root root 9760 Dec 23 17:47 python2.7*
    -rwxr-xr-x 1 root root 1687 Dec 23 17:47 python2.7-config*
    -rwxr-xr-x 2 root root 12618 Dec 23 18:08 python3.4*
    -rwxr-xr-x 2 root root 12618 Dec 23 18:08 python3.4m*
    -rwxr-xr-x 1 root root 3011 Dec 23 18:09 python3.4m-config*
    -rwxr-xr-x 1 root root 236 Dec 23 18:09 pyvenv-3.4*

    I got following errors when running python:

    > python2.7
    python2.7: error while loading shared libraries: cannot open shared object file: No such file or directory

    > python3.4
    python3.4: error while loading shared libraries: cannot open shared object file: No such file or directory

    Ran following as root, not use sudo ldconfig to ensure /usr/local/lib path is recognized


    cd /usr/local/bin

    ldd python2.7 => (0x00007fff9a151000) => /usr/local/lib/ (0x00007fb77d4d0000) => /lib64/ (0x00007fb77d2b3000) => /lib64/ (0x00007fb77d0ae000) => /lib64/ (0x00007fb77ceab000) => /lib64/ (0x00007fb77cc27000) => /lib64/ (0x00007fb77c892000)
    /lib64/ (0x00007fb77d8bd000)

    ldd python3.4 => (0x00007fff799d9000) => /usr/local/lib/ (0x00007f2fa84a8000) => /lib64/ (0x00007f2fa828b000) => /lib64/ (0x00007f2fa8086000) => /lib64/ (0x00007f2fa7e83000) => /lib64/ (0x00007f2fa7bff000) => /lib64/ (0x00007f2fa786a000)
    /lib64/ (0x00007f2fa895e000)

    Both paths are now seen: => /usr/local/lib/ (0x00007fb77d4d0000) => /usr/local/lib/ (0x00007f2fa84a8000)

    Everything working as expected:

    Python 2.7.9 (default, Dec 23 2014, 17:47:28)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.

    Python 3.4.2 (default, Dec 23 2014, 18:07:56)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
    Type “help”, “copyright”, “credits” or “license” for more information.

    Thanks Daniel Eriksson for creating this document.

    Thanks everyone else for your posts.


  85. Thanks for the informative write up. I just installed python3.4 on my CentOS 6.4 server and your steps worked perfectly except I used newer versions of coarse.

    Thanks, Again

  86. This is how instructions should be. They are complete, they are precise, and they explain why I am going through all of these steps. They even talk about alternatives. Thanks, Daniel!

  87. This is an extremely straightforward and easy to follow explanation. I’m a python newbie and I was up and running within minutes of reading this. It’s much appreciated. Thank you!

  88. If LDFLAGS appears to be confusing ./configure as so:

    configure: error: C compiler cannot create executables
    See `config.log’ for more details

    an alternate way to communicate the Python library path to the run-time linker worked for me:

    ./configure –prefix=/usr/local –enable-shared
    LD_RUN_PATH=/usr/local/lib make
    sudo make install

    The LDFLAGS=’Wl,-rpath /usr/local/lib’ method given in the tutorial worked for me until very recently (though I had to create /usr/local/lib first, as pointed out in a page linked to in a comment above), but with a recent CentOS 6 update that stopped working

    This was for Python-3.4.3 on CentOS 6.

  89. hi daniel,

    i got python2.7 installed on my fedora core 3 machine as alternative python using your doc

    But i m still getting same error yum module is not present

    System python version is still 2.3.4

    please help


  90. I carefully followed the instructions and have a good install of the two versions 2.7.6 and 3.4.3 – and I installed. I chose not to edit the so.conf file. I can get the version of each using the python3.4 -V and python2.7 -V. I installed PIP and even then installed Django with a succesful install. I installed virtualenv without error, as in here:

    pip2.7 install virtualenv
    virtualenv-2.7 my27project

    But when I type virtualenv-2.7 my27project I get that virtualenv-2.7 is not found. What do I do?

    Also – pyenv-3.4 is not found and pyenv without the suffix is not found.

    What can I do to correct these so I can test my django installation?


  91. Made this work by using pyvenv-3.4 and activating the virtual environment before installing django. That’s all well and good. I do have one remaing question – when I want to publish and use my django application how do I apply this virtual environemnt so at runtime apache uses this virtual environemnt to find my python 3.4 and use that?

  92. I’m a noob so I’ve been doing my fair share of install/reinstall lately , and now that I’ve come across this tutorial it won’t be because I broke Python the next time! This is excellent, thank you very much. Well explained, well guided, and complete. I changed a few things like 2.7.10 and 3.4.3 , and using dnf instead of yum, and it still went perfect.

  93. In the Shared Library section, the line with LDFLAGS=”-Wl,-rpath /usr/local/lib” can be rendered to include a dash. For me it appeared as “LD- FLAGS=”. Copy in firefox actually puts the correct text into the clipboard, but that’s just confusing! Perhaps put it in a block?

    Editing gives me nightmares.

    Regarding another comment above, I'm not sure that setting LD_RUN_PATH= gets recorded in the compiled binary the way -rpath does.

    1. The markup engine ate part of my comments: There was a newline in the middle of LDFLAGS, and I suggested putting the mis-rendered line in a “code block”.

  94. I would add a step to ‘strip’ the shared library which makes it much smaller and matches the vendor implementation (at least RedHat). ie

    strip /usr/local/lib/

  95. Thanks for posting this it has been extremely useful. Can any of the initial yum installs be safely removed once the compile is complete?

  96. Hi Daniel, Your blog was very helpful and I had followed these steps to install Django 1.7 inside a virtualenv (using Python 2.7.8) on CentOS 6.7. However, I recently tried to upgrade Django to version 1.8.8 using pip2.7 install –upgrade django==1.8.8 and consistently hit a segmentation fault after the package is downloaded. Any ideas as to what might be going wrong?

  97. Thank you, it works for py2.7.11 & py3.5.1 on CentOS Minimal 6.6. Well, except that py3.5.1 ships with setuptools and pip already.

    Here are the last few lines of sudo make && sudo make altinstall (of py3.5.1) ‘s output:

    Ignoring indexes:
    Collecting setuptools
    Collecting pip
    Installing collected packages: setuptools, pip
    Successfully installed pip-7.1.2 setuptools-18.2

  98. Daniel, thank you for such great guide … well explained and all commands worked as expected. Not like other guides out there that only half the commands work. The only issue I found is the location of the file which is in another location on bitbucket. But everything else worked perfectly !!! I wish there was a guide like this to install QIIME on a Centos based HPC.


Leave a Reply