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!

2
  • 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 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. Commented Oct 13, 2014 at 18:03
  • why do you need both? Commented Oct 13, 2014 at 18:51

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you very much for your answer! How should I install pip3.3? sudo apt-get install python3.3-setuptools doesn't work.
@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.)
@Sean: Of course you can always follow the generic pip installation instructions 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.
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: 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?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.