10

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 http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz  
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

7

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.

  • 1
    are you sure? I don't think so, do you have any source for what you tel ? – Yusef Mohamadi Jan 17 '16 at 13:19
  • Maybe this will give you some hint what may happend: LINK – Jaur Jan 17 '16 at 13:29
  • thanks for you attention,but after research I think yum have some problem with python 3 stackoverflow.com/questions/23589971/yum-not-working – Yusef Mohamadi Jan 17 '16 at 13:35
  • so can you tell me how can I install pyquery 1.2.4? I try pip install python-pyquery==1.2.4 but getting error – Yusef Mohamadi Jan 17 '16 at 13:48
  • Maybe this will help: pip install pyquery==1.2.4 – Jaur Jan 17 '16 at 14:55
7

Put the below line in ~/.bashrc file:

alias python=/usr/local/bin/python2.7

Now execute the command:

source ~/.bashrc

Now type python to check which version it has mapped to. It maps to Python2.7.

0

follow this link: https://ruter.github.io/2015/12/03/Update-python/ I did what it says and python is updated successfully. If you meet error:

ImportError: cannot import name HTTPSHandler

just install openssl:

yum install openssl openssl-devel -y

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

-1

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.

  • Is this really still true? Python 2.6 was EOL on October 2013 and hasn't had security updates since then. – jwadsack Aug 29 '16 at 19:11
  • 1
    It's EOL upstream, but the packages in CentOS will be maintained with security fixes for the lifetime of each release (which matches the lifetime of the corresponding RHEL release). That means that Python 2.4 (EL5) is "supported" until 2017-03, and Python 2.6 (EL6) is "supported" until 2020-11. – carlwgeorge Aug 31 '16 at 14:13
-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.