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:

Unicode

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/ld.so.conf 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/ld.so.conf 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 ez_setup.py file you downloaded earlier and just run it after you activate your new sandbox.

Changelog

2014-03-15

  • Examples updated with Python 3.3.5.

2014-02-16

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

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

    Reply
  2. astaza

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

    Reply
    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

      Reply
      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 ld.so.conf, and everything was good.

        Greg–

        Reply
  3. michael

    how do add something to the pythonpath of python2.7

    Reply
  4. kevin

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

    Reply
  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”.

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

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

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

    Reply
    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”

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

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

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

      Reply
      1. francis

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

        Reply
  9. David Phillips

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

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

    Reply
  10. Pingback: Broken python installation on CentOS 5.8 | UmeedainTimes.com

  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: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

    Reply
        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

          Reply
  12. Pingback: Хостинг WSGI з nic.ua | 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.

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

    Reply
  15. anshul

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

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

      Reply
  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 setup.py 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/smtpd.py -> 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/smtpd.py from 644 to 755
    /usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
    make: stat: Modules/config.c.in: Permission denied
    make: *** No rule to make target Modules/config.c.in', needed by Makefile’. Stop.
    —————————————————————————————
    There is nothing at all in my /usr/local/bin.

    Any suggestions?

    Reply
    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 sitecustomize.py 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 setup.py 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.

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

        Reply
        1. Cris

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

          Reply
        2. Sasha

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

          Reply
          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

  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 ?

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

      Reply
  19. Shane

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

    Reply
  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*

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

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

      Reply
      1. Gurdeep

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

        Reply
  23. Santosh Marigowda

    Thank you. Worked perfect.

    Regards
    Santosh

    Reply
  24. pay sol

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

    Reply
  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

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

    Reply
  27. vigikaran

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

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

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

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

      Reply
  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,
    Philip

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

      Reply
      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?

        Reply
  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,
    Philip

    Reply
    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

      Reply
  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
    $yum
    -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,
    Philip

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

      Reply
  32. IngyHere

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

    Running pycrypto-2.6/setup.py -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!

    Reply
    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/bin/python2.7
      /usr/local/include/python2.7 (dir)
      /usr/local/lib/libpython2.7.a
      /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.

      Reply
  33. Rolando Lucio

    very useful article, great work, thanks!

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

    Reply
  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 setup.py install, I receive the error: “-bash: python3.3: command not found”. Any ideas on how to fix this?

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

    Reply
  39. Pingback: linux tips linux命令锦集

  40. Rohit

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

    Reply
  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

    Reply
      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) ?

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

          Reply
          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?

    Reply
  43. Andrew

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

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

      Reply
  44. Florian La Roche

    Hello,

    I’ve just updated to python3-3.3.1 as rpm packages on:
    http://jur-linux.org/download/el-updates/6/

    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

    Reply
  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?

    Reply
  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

    Reply
  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

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

    Reply
  50. Jorge Dollisen

    Thank you so much. This is very helpful!

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

    Reply
  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 python.org. does not include -devel files at all?? I have been all over python.org’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.

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

    Reply
  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?

    Reply
  59. ChrisL

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

    Reply
  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?

    Thanks

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

          Reply
  61. Mike

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

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

    Reply
  64. Pingback: By: Walt | Centos 6 RHEL Linux | Scoop.it

  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?

    Reply
  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 https://pypi.python.org/pypi/distribute/0.7.3 using http.

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

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

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

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

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

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

  69. Pingback: Instalar Python | Blog de Mario Javier

  70. Camps

    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:

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

    Any ideas?

    Regards,

    Camps

    Reply
  71. arun

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

    Reply
  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/mydomain.es

    Thanks

    Reply
    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

      Reply
  73. Pingback: Python 2.7 on Centos

  74. unais

    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.

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

    Reply
    1. romainRHU

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

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

    Reply
  78. Amit

    Hi I followed the steps to install python2.7 but still I run into following errors:
    http://pastebin.com/gAPLRLc2

    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.

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

    Reply
  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

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

    Reply
  83. Anonymous

    When build your python, be sure to put
    “–enable-uncode=ucs4″

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

    Reply
    1. Anonymous

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

      Reply
  84. Jeff Williams

    Help im getting
    ERROR: certificate common name “*.a.ssl.fastly.net” doesn’t match requested host name “pypi.python.org”.

    Reply
    1. John

      Add
      –no-check-certificate
      to the request, either just after the wget or at the end of the line.

      Reply
  85. strider

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

    Reply
  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
    Reading http://pypi.python.org/simple/virtualenv/
    Download error on http://pypi.python.org/simple/virtualenv/: unknown url type: https — Some packages may not be found!

    or
    # pip -V

    ImportError: No module named ‘_ssl’
    )

    Reply
    1. Nick

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

      yum install openssl-devel

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

    Reply
  88. Hang Pan

    Running perfectly well.
    Thanks a lot, Daniel.

    Reply
  89. Pingback: I ran into Python | Private Dock

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

  91. Alfonso

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

    Thanks

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

    Reply
  94. Oscar Frank

    http://namhuy.net/908/how-to-install-iftop-bandwidth-monitoring-tool-in-rhel-centos-fedora.html

    Requirements:
    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
    wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
    ./configure
    make
    make install

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

    http://askubuntu.com/questions/400343/trying-to-create-a-python-virtual-environment-but-getting-oserror

    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.

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

    Reply
    1. Daniel Eriksson Post author

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

      Reply
  98. x

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

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

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

    numpy
    scipy
    matplotlib
    ipython
    pandas
    sympy
    nose

    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/shellapp.py in (key)
    221 shell = self.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/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
    2918 from IPython.core.pylabtools import import_pylab
    2919
    -> 2920 gui, backend = self.enable_matplotlib(gui)
    2921
    2922 # We want to prevent the loading of pylab to pollute the user’s

    /usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py 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/interactiveshell.py 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/inputhook.py 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)
    529

    /usr/local/lib/python3.3/site-packages/IPython/lib/inputhook.py 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/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
    1798 baseName = baseName + ext
    1799 interactive = 0
    -> 1800 self.tk = _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?

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

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

        Reply
  100. Jason

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

    Reply
  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 ?

    Reply
  102. JC

    before i could successfully do:
    python2.7 ez_setup.py

    i had to:
    yum install zlib-devel

    then redo the python install:
    make&&make altinstall

    then it works

    Reply
    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?

      Reply
  103. Henryx

    Hi,

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

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

      Reply
  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

    Reply
  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 ?

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

      Reply
  108. Alaa

    Dear Daniel,
    Why do i get this error when trying to execute this command
    python3.4 ez_setup.py


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

    ?
    Best regards

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

    Reply
  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

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

    /usr/local/lib64

    to /etc/ld.so.conf to make it look like the following.

    include ld.so.conf.d/*.conf
    /usr/local/lib
    /usr/local/lib64

    This solves the potential error of:

    problem loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory

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

    Reply
  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.”

    to

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

    Reply
  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?

    Reply
  117. Chris Arnesen (@ChrisArnesen)

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

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

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

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

  119. cheryl

    Great Post Extremely Helpful !!!!
    Thanks
    Cheryl

    Reply
  120. Luis G

    Instead of adding a line to /etc/ld.so.conf, I think it’s a better idea to create a separate .conf file into the /etc/ld.so.conf.d.
    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/ld.so.conf.d/python-alt.conf

    And it’s also easier to revert:
    rm /etc/ld.so.conf.d/python-alt.conf

    Reply
  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

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

        Reply
  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,

    Satz.

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

    Reply

Leave a Reply