Ubuntu 10.04 安装 Python 2.7

本文详细介绍了如何在Ubuntu 10.04上将默认的Python 2.6.5升级到2.7.6。升级过程包括下载Python源码,解决依赖问题,以及安装第三方Python包如pyOpenSSL的步骤。在升级过程中可能会遇到缺少-dev包的警告,可以通过安装libreadline-dev和libgdbm-dev来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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-py2.7-linux-x86_64,cffi-0.8.1-py2.7-linux-x86_64 and pycparser-2.10-py2.7


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.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值