The issue
Certain important Python libraries require the zlib module. By default, Python2.6 does not include zlib as part of the standard library without some extra work.
If you're on a relatively new Ubuntu version but still need to maintain backwards compatability with a Python2.6 program, shared library directory changes in Ubuntu can lead to conflicts.
Prerequisites
Ensure the following packages are installed
$ sudo apt-get install zlib1g zlib1g-dev
Download the latest source of Python2.6 (which is Python 2.6.9 at the time of this article)
~$ cd /tmp
/tmp$ wget "https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz"
/tmp$ tar -xf Python-2.6.9.tgz
Solution
This post on UbuntuForums outlines the issues with Python2.6 compatibility with newer Ubuntu versions.
It is Ubuntu's "fault". They changed where shared libraries are placed in
order to support multiple architectures better (eg both x86 and x86_amd64 on the
same machine) in a way that diverges from how it has always been done in the
past.
...
...
Upstream Python is being patched, but that doesn't really help as they are only
doing it with current versions of Python
So we need to locate the libz shared library file and move it to a place where Python can locate it.
Locating the libz file
First, cd to the /lib directory
$ cd /lib
Now we will find the exact libz shared library file via the find command
find ./ -name "libz.so.1"
./x86_64-linux-gnu/libz.so.1
My libz.so.1 file was located at ./x86_64-linux-gnu/libz.so.1. Your libz file may be in a different directory.
We will now create a symlink to libz.so.1 file that was returned by the find command above.
sudo ln -s ./x86_64-linux-gnu/libz.so.1 libz.so
Recompile
cd Python-2.7.11
在编译前先在/usr/local建一个文件夹python2_7_11(作为python的安装路径,以免覆盖老的版本)
mkdir /usr/local/python2_7_11
开始编译安装
./configure
make
make install
此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
mv /usr/bin/python /usr/bin/python_old
再建立新版本python的链接
ln -s /usr/local/python2_7_11/bin/python2.7 /usr/bin/python
Verification
Python 2.7.11 (default, Aug 15 2016, 09:58:47)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
>>>
forward from: http://joequery.me/guides/python26-no-module-zlib/