How to install Python 2.7 and Python 3.3 on CentOS 6

By | 2014/02/16

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.

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

  1. Farhan

    Thanks Daniel. I second Onur.

    I have two serpents now :)

  2. astaza

    after all this steps
    i got this error when i use yum
    No module named yum
    how to fix it
    thank you

    1. Daniel Eriksson Post author

      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. Greg Silverman

        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. Matt

          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. joao

            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…

  3. michael

    how do add something to the pythonpath of python2.7

  4. kevin

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

  5. Pingback: Backing up to Amazon Glacier | Jacob Allred

    1. Daniel Eriksson Post author

      You need to have the sqlite-devel package installed before you configure and make python. Install it with “yum install sqlite-devel”.

  6. Erik

    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. Balazs

      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!

  7. sanjay

    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. sanjay

      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. Scott

        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.

  8. krunal

    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. Daniel Eriksson Post author

      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. francis

        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

  9. David Phillips

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

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

  10. Pingback: Broken python installation on CentOS 5.8 |

  11. Daniel Sieradski

    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. Dan

          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. Konstantin

      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

  12. Pingback: Хостинг WSGI з | Roman Yepishev

  13. Cheet

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

  14. Tin Tvrtković

    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.

  15. anshul

    hey thanks for the tutorial. How do we point django’s default python to this python ?

    1. Daniel Eriksson Post author

      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.

  16. Dave

    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. Dave T

      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. Dave M

        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. Cris

          Thanks, Dave. That did the trick for me. And thank you, Daniel, for such a useful guide.

        2. Sasha

          You want to do sudo make && sudo make altinstall — need to sudo on both commands.

          1. sgj

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

          2. derrick

            Thank you!!! I was not adding the second sudo

        3. sg

          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

  17. Pingback: Run in a CentOS server

  18. Mihalache

    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. Daniel Eriksson Post author

      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.

  19. Shane

    Smooth as silk, thanks very much for taking the time to put this together

  20. Pingback: Installing Python 2.7 on CentOS 5 | My Blog

  21. jOHN

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

  22. d.code

    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. Daniel Eriksson Post author

      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.

      1. Gurdeep

        I Want to run twissted protocol inside python 2.7 as it is working with python 2.6.6 . Please suggest

  23. Santosh Marigowda

    Thank you. Worked perfect.


  24. pay sol

    Thanks buddy , easiest but best routine. I’m going to check your other posts.

  25. Aníbal

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

  26. Daniel Eriksson Post author

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

  27. vigikaran

    i have intsall python using altinstall command, but still it show version 2.4
    how to resolve it

    1. Daniel Eriksson Post author

      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).

  28. Andy Duong

    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. Daniel Eriksson Post author

      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.

  29. Philip

    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. Daniel Eriksson Post author

      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. Josh

        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?

  30. Philip Prathipati

    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. Daniel Eriksson Post author

      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

  31. Philip Prathipati

    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. Daniel Eriksson Post author

      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.

  32. IngyHere

    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. Daniel Eriksson Post author

      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.

  33. Rolando Lucio

    very useful article, great work, thanks!

  34. Count Schemula

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

  35. Pingback: Living Cosmos

  36. chris

    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?

  37. Pingback: CentOS6にpython2.7を入れる | ちいさな創々

  38. Eric

    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.

  39. Pingback: linux tips linux命令锦集

  40. Rohit

    Sweet !!!…This worked like a charm, not even a single hiccup.

  41. Jerry

    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. Dave T

        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. Jerry

          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. Dave T

            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.)

  42. Shamunda

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

  43. Andrew

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

    1. Mark

      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.

  44. Florian La Roche


    I’ve just updated to python3-3.3.1 as rpm packages on:

    This is based on the newest Fedora rpm to compile on RHEL6, any additional
    testing more than welcome for people who don’t want to recompile themselves.

    best regards,

    Florian La Roche

  45. Dan

    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?

  46. bela

    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

  47. Pingback: How to install Python 2.7 – On Windows, Ubuntu and CentOS | Buzz Atom - Your Way Into The Core of Nimbuzz

  48. Mohamed Ezz

    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

  49. Nicola Musatti

    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.

  50. Jorge Dollisen

    Thank you so much. This is very helpful!

  51. Pingback: Not RSS 2 Email — Half-Elf on Tech

  52. jerry

    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.

  53. Pingback: How to install Python 2.7 and 3.3 on CentOS 6 |...

  54. Phil

    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.

  55. Vince E

    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.

  56. Pingback: Instalar Python 2.7 en CentOS 6 con mod_wsgi de forma segura | Hello, IT.

  57. Pingback: Comment on How to install Python 2.7 and 3.3 on...

  58. GaryE

    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?

  59. ChrisL

    This worked fantastically on CentOS 6.XX. Thank you very much!

  60. Yann Sagon

    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. Daniel Eriksson Post author

          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!

  61. Mike

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

  62. Pingback: Installing and compiling Python 2.7 on Centos 6.3 | Information Assurance

  63. Walt

    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.

  64. Pingback: By: Walt | Centos 6 RHEL Linux |

  65. Bert

    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?

  66. Alan

    Daniel, your procedure is awesome! Thanks. I successfully installed Python 2.7.5 and distribute 0.7.3 on CentOS 6.4. I ran into an issue using wget to download distribute 0.7.3 (seems to be a certificate error), so I downloaded it directly from using http.

  67. Will

    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. Dave T

      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. Will

        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. Glenn N

          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. Krishan Gupta

        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.

  68. Pingback: CentOS 6.4 PYPI本地源制作 » 陈沙克日志

  69. Pingback: Instalar Python | Blog de Mario Javier

  70. Camps


    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?



  71. arun


    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 !!

  72. Jose Ramon Leon

    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. Chatonda Mtika

      “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

  73. Pingback: Python 2.7 on Centos

  74. unais


    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.

  75. Pingback: Sudoer statement syntax to source virtualenv activate file | BlogoSfera

  76. python27

    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. romainRHU

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

      1. Peter

        My too. How do I install Numpy for Python 2.7 being installed as altinstall?

  77. Glenn Nelson

    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.

  78. Amit

    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.

  79. Pingback: CentOS | Pearltrees

  80. Noel Ferreria

    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.

  81. Chatonda Mtika

    “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

  82. Rishi

    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.

  83. Anonymous

    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. Anonymous

      Sorry, “–enable-uncode=ucs4″ should be “–enable-unicode=ucs4″, a typo.

  84. Jeff Williams

    Help im getting
    ERROR: certificate common name “*” doesn’t match requested host name “”.

    1. John

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

  85. strider

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

  86. Cupy

    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’

    1. Nick

      This also happen if you do not have openssl-devel package:

      yum install openssl-devel

  87. strider

    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.

  88. Hang Pan

    Running perfectly well.
    Thanks a lot, Daniel.

  89. Pingback: I ran into Python | Private Dock

  90. Pingback: Monday, December 2nd, 2013 | DayByDayFindings

  91. Alfonso

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


  92. Pingback: How to install Python 2.7.3 on CentOS 6.2 | yetaocloud

  93. Gaurav

    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 :)

  94. Oscar Frank

    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

  95. Pingback: Bruteforce Facebook Login with Python Script | franx47

  96. Mio

    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.

  97. Peter

    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.

    1. Daniel Eriksson Post author

      I will update the post with info about installing Setuptools later tonight. Distribute is deprecated.

  98. x

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

    1. Daniel Eriksson Post author

      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.

  99. Jason

    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. Dave T

      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. Jason

        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.

  100. Jason

    Daniel, you don’t have any insight into the problem I am experiencing above?

  101. Dave T

    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 ?

  102. JC

    before i could successfully do:

    i had to:
    yum install zlib-devel

    then redo the python install:
    make&&make altinstall

    then it works

    1. Daniel Eriksson Post author

      That is part of the preparations step of the guide. Are my instructions wrong or did you not follow the guide?

  103. Henryx


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

    1. Daniel Eriksson Post author

      Thank you, I tried this and it works just fine for both 3.3 and the recently released 3.4. I’ll include your recommendation in my next update.

  104. Sasha

    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

  105. Pingback: my emacs and linux engineering note. | nova0302

  106. Pingback: How to install python 2.7 on CentOS 6.5 | nova0302

  107. dubi

    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. Daniel Eriksson Post author

      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.

  108. Alaa

    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. sandipgSandip

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

  109. Pingback: Quora

  110. Sean

    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!

  111. Sean

    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

  112. Pingback: Python 2.7 and Python 3.3 on CentOS 6 Reliable Penguin - Blog

  113. Joost VanDorp

    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

  114. marques

    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.

  115. Doug B. Feltsom

    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.

  116. ohyos.isolt

    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?

  117. Chris Arnesen (@ChrisArnesen) 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.

  118. Pingback: Python, Flask, WSGI 설정 삽질 ㅠ on CentOS 6 | I'm Nova.

  119. cheryl

    Great Post Extremely Helpful !!!!

  120. Luis G

    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/

  121. Pingback: Linux tricks | Pearltrees

  122. analog

    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

      1. Daniel Eriksson Post author

        Yes, new version of tar knows how to unpack both gzip, bzip2 and xz archives without having to pass it as a command line option.

  123. Pingback: Installing Grunt on CentOS 5.10 | Josh's Blog

  124. Satheesh

    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,


  125. Nick Shaw

    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.

  126. Naween Ghimire

    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 ?

    1. Naween Ghimire

      Figured out the issue, apparently we need to pass –insecure option to the script at the time of execution:

      python2.7 –insecure

  127. Rakesh

    Thank you so much for this info. very useful!!

  128. mc

    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. steez

      Running separate sudos seemed to work for me:
      sudo make
      sudo make altinstall

    2. sg


      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

  129. Pingback: Fix Ez_setup Syntax Error Windows XP, Vista, 7, 8 [Solved]

  130. Pingback: Fix Python Error Windows XP, Vista, 7, 8 [Solved]

  131. Pingback: Fix Blender Error Python Auto-execution Disabled Windows XP, Vista, 7, 8 [Solved]

  132. chirale

    Excellent howto! Thank you for sharing these easy steps to have more version of python running on the same box.

  133. Pingback: How to get W3af 1.6 running on a CentOS 6.5 system with Python 2.7.6 | Tim Blog

  134. sudocode

    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.

  135. Pingback: Fix Configure Error Zlib Not Installed Centos Windows XP, Vista, 7, 8 [Solved]

  136. Bob


    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?


  137. Pingback: Fix Ez Setup Py Error Windows XP, Vista, 7, 8 [Solved]

  138. sg

    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.


  139. Pingback: How to install Python 3.4 on CentOS |

  140. Alpha Monk

    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

  141. Pingback: Amazon Linuxにpipをインストール(pip3は失敗でyumで環境作るのが良いらしい)-はじめてのAWS | kazsoga(曽我一弘)ブログ

  142. Bernd Bausch

    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!

  143. Ed

    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!

  144. Pete Harlan

    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.

  145. Pingback: CentOS 6.5にPython 2.7をインストールしApacheで使用 | Akashic Records

Leave a Reply