How to Upgrade Python on CentOS
- Written by Vanessa Vasile
- Published in Howto, Linux
- 8 Comments
If you’re running CentOS, you’re
probably a few versions behind on Python. Currently, the version packaged for CentOS 5 and 6 is 2.6. Contrary to what the title of this post implies, you actually cannot safely upgrade Python on any Redhat distribution. If you’re feeling brave, try this to see why:
yum remove python
Warning, do not pass a ‘-y’ to the above command. All you’re doing here is viewing output. Hit CTRL+C once it prompts to continue, and no changes will be made to your system.
If you ran the command above, you’ll see all the packages that depend on Python, most all of which will break (including Yum itself) if you alter the system-installed package or attempt to upgrade. Therefore, if you need a newer version of Python, the only safe way to do this is to install it alongside the system version.
This example is for installing Python 2.7, but you can easily do similar steps for version 3.3, etc. There are a couple ways to do this:
This is the best way to install additional versions of Python since their updates will be maintained automatically. First, install the EPEL repo:
yum install python34*
The exact version may change depending on what version of CentOS you are running. The additional binaries will be in /usr/bin, for example:
Just download your preferred version from python.org.
tar -xvzf Python-2.7.6.tgz
And that’s all that’s to it! Now any scripts that require the alternate version should have the following shebang:
If you need to use pip to install modules for your alternate version, make sure to use the correct one:
First off excellent article.
One minor issue:
looks like it is a single hyphen, when it should be a double hyphen! #fontproblems
lol, just thought I would point that out in case any newbies had some trouble.
I got distracted when i first came to your website, but then went back to it. Somehow i closed over the most important part of your wording. I ran the “yum remove python” and now 70+ low traffic websites are offline. I’ve never made a mistake this bad in my 17 years a system admin. How can i be so stupid?
I’m having a bad day. Good news is, this gives me a reason to upgrade to CentOS 6.x rather than being stuck on on CentOS 5.8.
In your post you wrote:
[code] ./configure –prefix=/usr/local [/code]
THat’s a hypehn not a minus sign and it should be a double minus sign.
[code] ./configure --prefix=/usr/local [/code]
in the post it is correct, but WordPress formats it oddly.
Pingback: Cassandra Basics | Site Title
Great information. If I need to run a website with Phyton, what I need to do? I want have scripts in any directory inside public_html
I will create a ticket for this question inside your consultation system.
Followed every step. But, still hard luck.
Need Python 2.7.3
# yum -y install centos-release-SCL
# yum -y install python27
# scl enable python27 bash