Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The command python opens a Python 2.7.6 environment. If I want to interpret a Python 3 script, I need to rewrite the command to python3.

I've just installed the numpy package. In order to test the successful installation, I run the command import numpy. It works well when using the python command. However, python3 does not find the package.

How is this possible? Do these two commands use different path variables? How can I change the behavior?

share|improve this question

You're absolutely right, they use different PYTHONPATHs.

You can think of Python 2.x and Python 3.x as completely different programming environments. And yes, they store their packages in different locations.

To get numpy working, you can type:

sudo apt-get install python3-numpy

If you want to find out where exactly a package is kept, you can look at the module objects __path__ attribute:

>>> import numpy
>>> numpy.__path__

You can also install python3-pip and then run pip3 install whatever to install packages for Python 3 with Pip, for packages that aren't available in Ubuntu as python3-whatever.

In case you're confused about the difference between distutils, setuptools, easy_install, pip and the rest, use pip. That's the cool one. :)

share|improve this answer

Indeed, both are importing modules from different locations:

  • Python2.7: /usr/lib/python2.7/dist-packages/numpy/
  • Python3.x: /usr/lib/python3/dist-packages/numpy/

To be able to import numpy with both interpreters, be sure to install their corresponding packages:

  • Python2.7: sudo apt-get install python-numpy
  • Python3.x: sudo apt-get install python3-numpy
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.