How can I upgrade Python to 2.7.9 on Ubuntu 14.4?

Solution 1:

ppa:fkrull/deadsnakes is the latest version of python2.7

sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get upgrade

It will upgrade python to 2.7.10

Solution 2:

You can use pyenv:

 git clone https://github.com/pyenv/pyenv.git ~/.pyenv
 git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv

Then add

   #   for PyEnv
  export PYENV_ROOT="$HOME/.pyenv"
  export PATH="$HOME/.pyenv/bin:$PATH"
  export PATH="$HOME/.pyenv/shims:$PATH"
  eval "$(pyenv init -)"

to .bash_profile then you can see the python version you want to install or update:

pyenv install --list

want python 2.7.10? you can try:

 pyenv virtualenv 2.7.10

Hope it can help you.


Solution 3:

I'm not a fan of previous answers suggesting installing from various PPAs. No disrespect intended, but I don't know the people who built them and I have no idea what might be in there. In any environment where someone has to answer to a security professional that practice would be frowned upon.

I just found that downloading 2.7.9 from source and installing it side-by-side was a good start. This awesome blog post covered the steps. (recreated here to conform to stack overflow guidelines)

wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
tar xfz Python-2.7.9.tgz
cd Python-2.7.9/
./configure --prefix /usr/local/lib/python2.7.9
make
make install

Test if the version works

/usr/local/lib/python2.7.9/bin/python -V
Python 2.7.9

Now that I have 2.7.9 installed I can call it directly or symlink to it from wherever I want. (or copy it into a virtualenv etc.)

And note that I got here from a situation where I was getting insecure platform warnings, and SNI Missing warnings. Which led me here. I imagine many people are finding this question through the same path. And if that's why you're here this snippet may be of use to you too

pip install urllib3[secure]

Solution 4:

Here is new upgraded third party repository:

sudo add-apt-repository ppa:jonathonf/python-2.7
sudo apt-get update
sudo apt-get install python2.7
python --version

Solution 5:

You can go to the python.org and download the .tar.gz file compile and install it. You will need the basic tools in order to compile the source code. I don't remember if the "build-essential" package will suffice but give it a try.