Python: python zlib module install 解决办法

浏览: 1311

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 --prefix=/usr/local/python2_7_11
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/

推荐 0
本文由 Yuchi608 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

1 个评论

就是介绍了安装了2.7的版本?

要回复文章请先登录注册