3

I'm a newbie to Ubuntu, so I'm sorry if question is too dumb. How can I install Python package to already installed local version of Python?

Ubuntu 14.04, Python 2.7.10 /usr/local/bin/python2.7, package I need to install is zlib

Thanks in advance

SOLVED

  1. $ sudo apt-get install zlib1g-dev
  2. $ wget python.org/ftp/python/2.7.10/Python-2.7.10.tgz
  3. $ tar xfz Python-2.7.10.tgz
  4. $ cd Python-2.7.10/
  5. $ ./configure --prefix /path/to/python/ --enable-ipv6
    (in my case path was /usr/local )
  6. $ make
  7. $ sudo make install

Check:
$ python2.7 -c "import zlib; print(zlib.version)"

Grand thanks to all of you guys for helping with this problem!

olexa
  • 55

6 Answers6

5

As far as I know, there is no Python package that contains zlib because that's already included into the standard library.

Try the command below to see whether the zlib Python package is available and which version it has:

  • for Python 2.x:

    python -c "import zlib; print(zlib.__version__)"
    
  • for Python 3.x:

    python3 -c "import zlib; print(zlib.__version__)"
    

On my system, it outputs 1.0 for both Python versions.

Byte Commander
  • 110,243
4

None of the existing answers is incorrect, but similarly don't explain why you're having the problem you are, or how to fix it. Let's clear up some things:

  • zlib is a builtin, not a packaged thing. Virtualenvs are great things but won't help here.
  • If you don't have it, it wasn't built when Python was built.
  • You need the zlib development libraries in order for Python to be linked to it. If the ./configure step can't find it, it'll disable it from your build.

So that having been said, sudo apt-get build-dep python2.7 will be the sanest, quickest way to get all the build dependencies for a "typical" Python build.

But then you need to reconfigure, recompile and reinstall your version of Python. Just installing the build requirements won't retroactively link it in.

Oli
  • 299,380
2
  1. $ sudo apt-get install zlib1g-dev
  2. $ wget python.org/ftp/python/2.7.10/Python-2.7.10.tgz
  3. $ tar xfz Python-2.7.10.tgz
  4. $ cd Python-2.7.9/
  5. $ ./configure --prefix /path/to/python/ --enable-ipv6
    (in my case path was /usr/local )
  6. $ make
  7. $ sudo make install

check: $ python2.7 -c "import zlib; print(zlib.version)"

Grand thanks to all of you guys for helping with this problem!

olexa
  • 55
0

I highly recommend using virtualenv for a local install of Python that has the same minor version as the one that comes with Ubuntu (2.7.x), I'm quite new myself and had a lot of issues attempting to install packages to a local version without it, whereas with it you can simply create and activate a new environment and install to your hearts content without changing the global package list.

User guide: http://virtualenv.readthedocs.org/en/latest/userguide.html

There's an answer here for taking an already installed python version and creating a virtualenv with that version. Once you activate the environment you should then be able to check if you have zlib with that version by default, and install it if you don't have it already. https://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv

Cral
  • 11
0

You need to install the zlib1g-dev package and then run: sudo apt-get build-dep python2.7

After installing the dev package, continue to install the zlib package.

If the above thing does not work:

  1. download the source package for your Python (in this case wget python.org/ftp/python/2.7.10/Python-2.7.10.tgz)
  2. run ./configure --prefix=/path/to/python
  3. make
  4. make install
olexa
  • 55
Jay T.
  • 264
0

This solution I found on python.org compilation page.

sudo apt-get build-dep python3.6

If that package is not available for your system, try reducing the minor version until you find a package that is available in your system’s package manager.

I added the detail instruction on a blog post.

Obscure
  • 123