1

I currently have both Python 3.3 and 3.4 installed on my Ubuntu 14.04 system. When I install a Python package using pip3, for instance numpy,

sudo pip3 install numpy

it only installs it on Python 3.4. How can I install it on Python 3.3 as well?

Thank you!

Sean Bone
  • 3,368
  • 7
  • 31
  • 47
  • As a side note: Ubuntu has `numpy` (and friends) `apt`-able packages for all versions of Python that it has packages for, and according to [the scipy site](http://www.scipy.org/install.html) from 12.10 on they're good enough for most purposes. Of course you're probably not asking _just_ about `numpy`; you just used it as an example. – abarnert Oct 13 '14 at 18:03
  • why do you need both? – Padraic Cunningham Oct 13 '14 at 18:51

1 Answers1

2

Each Python installation has its own separate site-packages.

So, if you want to install for both, you have to install it twice. The way to do that is to use pip3.3 and pip3.4 instead of just pip3. (If you don't have pip3.3, you'll have to install it, of course.)


You may be wondering why each Python installation has its own separate site-packages.

Part of the reason is that newer Python versions often have new features, and an installer is allowed to install different things depending on your Python version. This isn't very common, but there's no real way for a package to signal that it's going to do different things for different versions, so setuptools has to assume they all will.

The .pyc compiled bytecode can also change between versions, even without the module doing anything different.

But the biggest problem, traditionally, is binary C extension modules. In general, a module compiled against one libpython won't work with a different Python version. In the case of 3.3+, however, this isn't always true—a module that uses only the "stable" API can be compiled for 3.3 and still work in 3.4 (assuming the same platform and build settings, of course).


Python is gradually evolving to deal with compiled modules (both .pyc and .so) that can be shared between installations, but it's not there yet.

In cases where you happen to know (or are willing to test) that they're compatible, you can always set up an extra shared-site-packages directory, configure your 3.3 to install to that directory, and configure both 3.3 and 3.4 to look at it. However, that's usually more work than it's worth.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • Thank you very much for your answer! How should I install `pip3.3`? `sudo apt-get install python3.3-setuptools` doesn't work. – Sean Bone Oct 13 '14 at 17:57
  • @Sean: How did you install Python 3.3, Python 3.4, and pip for Python 3.4? (But really, if this answer isn't trivial, it's probably Ubuntu-specific, and might be better answered on SuperUser or AskUbuntu or a similar site.) – abarnert Oct 13 '14 at 17:58
  • @Sean: Of course you can always follow the [generic `pip` installation instructions](https://pip.pypa.io/en/latest/installing.html) for 3.3 (but be careful to make sure it doesn't overwrite `pip` or `pip3`, or install somewhere that isn't on your `PATH`, etc.). But I think it would be better to have your package manager know what you've installed if it's at all possible. – abarnert Oct 13 '14 at 18:00
  • Again, thank you for your time. The `pip` generic installation guide doesn't actually answer my question, so I gave it an educated guess, but downloading `get-pip.py` and running `python3.3 get-pip.py` returns an error: `zipimport.ZipImportError: can't decompress data; zlib not available` – Sean Bone Oct 13 '14 at 18:11
  • @Sean: Yowza, how could `zlib` not be available? Does Ubuntu have a separate page for `pythonX.Y-zlib` maybe? Can you fire up `python3.3` and try `import zlib` and `import zip` to see what happens? – abarnert Oct 13 '14 at 18:40
  • Hmh... neither is avialable on 3.3. 3.4 has `zlib` but not `zip`. – Sean Bone Oct 13 '14 at 18:52
  • [This question](http://stackoverflow.com/questions/17899291/should-i-re-install-python-again-for-zlib-module), [this one](http://stackoverflow.com/questions/16447635/installing-distribute-in-python-3-3-ubuntu), and [this one](http://stackoverflow.com/questions/9328014/cant-not-install-distribute-zlib) may be relevant. They're a bit out of date, but the basics should still be true: If you installed Python 3.3 from a source distribution (whether with the package manager or without it), if `zlib1g-dev` wasn't installed at the time, you'll get a Python build without the `zlib` module. – abarnert Oct 13 '14 at 19:12