5

When I start Python 2.7, I can import zlib without a problem. Unfortunately, I need Python 2.6 for a specific project.

I tried installing it with this script I wrote:

apt-get install zlib1g-dev
mkdir /tmp/shell_scripts
cd /tmp/shell_scripts
wget http://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz
tar -xvzf Python-2.6.9.tgz
rm Python-2.6.9.tgz
cd Python-2.6.9
./configure --with-zlib
make
make install
./python setup.py install
cd /tmp
rm -r shell_scripts

When I type import zlib, I get an import error. I need zlib to install easy_install. Have you an idea what could be wrong?

Xiphias
  • 4,468
  • 4
  • 28
  • 51
  • `which python` says `/usr/local/bin/python` and starts Python 2.6.9, `which python2.6` says `/usr/local/bin/python2.6` and also starts Python 2.6.9. Python prints `Python 2.6.9 (unknown, Feb 28 2014, 22:49:43)` – Xiphias Feb 28 '14 at 22:00

1 Answers1

6

I found the solution in a blog: I had to build a symbolic link and set an environment variable. This is my working code:

apt-get install zlib1g-dev
cd /lib
sudo ln -s i386-linux-gnu/libz.so.1 libz.so

mkdir /tmp/shell_scripts
cd /tmp/shell_scripts
wget http://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz
tar -xvzf Python-2.6.9.tgz
rm Python-2.6.9.tgz
cd Python-2.6.9
make distclean
export LDFLAGS="-L/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"
./configure
make
make install
./python setup.py install
unset LDFLAGS
cd /tmp
rm -r shell_scripts

Now, import zlib no longer throws an error.

Xiphias
  • 4,468
  • 4
  • 28
  • 51
  • 1
    In my case `libz.so.1` was located at `/lib/x86_64-linux-gnu/libz.so.1` (Debian 8.0 jessie). – bwind Dec 07 '16 at 12:59
  • Adding `ln -s /lib/x86_64-linux-gnu/libz.so.1 libz.so` and `export LDFLAGS="-L/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"` did the trick for me when installing Python 2.7.1 on Debian Buster. – WorkingMatt Jun 15 '21 at 14:10