Upgrade Python from 2.6 to 2.7 on Centos 6.5
Andrew Mclaughlin
I want to update my Python version on server, my current Python version is 2.6 and I want upgrade it to 2.7. Plesk is installed in our server and I also have access to ssh.
How can I upgrade it in Centos 6.5?
I try below
Download Python and extract it
wget
xz -d Python-2.7.8.tar.xz
tar -xvf Python-2.7.8.tar Installation process
# Enter the directory:
cd Python-2.7.8
# Run the configure:
./configure --prefix=/usr/local
# compile and install it:
make
make altinstall
# Checking Python version:
[root@nicetry ~]# python2.7 -V
Python 2.7.8
export PATH="/usr/local/bin:$PATH" but when I type python --version it returns 2.6.6
5 Answers
I can't add comment yet, only answer: Centos relies on python 2.6 for yum. You may break your system and yum if switching to 2.7 globally.
7Put the below line in ~/.bashrc file:
alias python=/usr/local/bin/python2.7Now execute the command:
source ~/.bashrcNow type python to check which version it has mapped to. It maps to Python2.7.
follow this link: I did what it says and python is updated successfully. If you meet error:
ImportError: cannot import name HTTPSHandlerjust install openssl:
yum install openssl openssl-devel -yBTW, centos uses yum, and yum uses 2.6 python, if you follow the link, you would have python2.6 moved to /usr/bin/python2.6, so in:
vim `which yum`change #!/usr/bin/python to #!/usr/bin/python2.6
You can't change /usr/bin/python without breaking your server. Just use the one you installed to /usr/local/bin/python2.7, or switch to IUS packages for python27 (which will install to /usr/bin/python2.7. Either way, you need to leave /usr/bin/python alone.
It might be that python 2.7 got installed but you are supposed to use python2.7 for using that version.
Try checking python2.7 --version