Recently I went back to my Ubuntu 10.04 machine, and realized the default Python version is 2.6.5. So I decided to upgrade it to 2.7. At first I thought it was just a few clicks in the Synaptic, but it turned out to be needing a little bit more effort.
STEP 1. Go to
http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz
to download the most recent gzipped source tar ball. Then extract the files, cd to the extractedPython-2.7.6 folder, and do
./configure
make
sudo make install
The 'make install' by default will install Python 2.7.6 to /usr/local/bin and /usr/local/lib, while the Python 2.6.5, the one that is originally shipped with Ubuntu 10.04, is located in/usr/bin and /usr/lib. It appears that /usr/local/bin/python takes precedence over /usr/bin/python, and /usr/local/bin/python is just a soft link pointing to version 2.7.
lrwxrwxrwx 1 root root 7 2014-02-27 05:51 python -> python2
lrwxrwxrwx 1 root root 9 2014-02-27 05:51 python2 -> python2.7
-rwxr-xr-x 1 root root 5741439 2014-02-27 05:51 python2.7
So now Python 2.7.6 becomes the system default. When you type 'python' in terminal, you will see
Python 2.7.6 (default, Feb 27 2014, 04:40:57)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
During 'make', you may encounter a warning message like
Python build finished, but the necessary bits to build these modules were not found:
bsddb185 gdbm dl
imageop sunaudiodev readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
This is actually pretty common because we are missing the -dev addon to some modules. I installed librealine-dev andlibgdbm-dev from Synaptic. The rest are just obsolete modules, it is safe to ignore them.
----------------------------------------------------------------------------------------------------------
STEP 2. Very often we need to install additional 3rd party python packages. For example, pyOpenSSL. I downloaded pyOpenSSL-0.14 tar ball from
https://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.14.tar.gz#md5=8579ff3a1d858858acfba5f046a4ddf7
To install it, we need first to install setuptools. Manually, you can do
$ wget http://peak.telecommunity.com/dist/ez_setup.py
$ sudo python ez_setup.py
ez_setup is a short Python script that bootstraps setuptools installation. It will automatically download setuptools and make it available on sys.path. Then cd to the extracted pyOpenSSL-0.14 folder, and do
$ sudo python setup.py install
Then setuptools will start to install pyOpenSSL and, if necessary, all the missing dependencies. In my case, I need to also install six-1.5.2-py2.7,cryptography-0.2.1-
I had some problems while installing crytography-0.2.1. A error message pops up:
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
So I have to go to http://sourceware.org/libffi/ to download libffi-3.0.13.tar.gz (a portable foreign function library) and install it.
But then another error message shows up:
File "/usr/local/lib/python2.7/site-packages/cffi-0.8.1-py2.7-linux-x86_64.egg/cffi/api.py", line 56, in __init__
import _cffi_backend as backend
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
The reason is that by default, 'make install' will put libffi.so.6 in/usr/local/lib, but cryptography installation will look for it in/usr/lib. Just move the share library over, and the installation will continue without errors.