2

I've installed Python Numpy on Debian using...

apt-get install python-numpy

But when run the Python shell I get the following...

Python 2.7.10 (default, Sep 9 2015, 20:21:51) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named numpy 

When I view the contents of /usr/local/lib/python2.7/site-packages/ I noticed numpy is not list.

If I install it via pip i.e pip install numpy it works just fine, However, I want to use the apt-get method. What I'm I doing wrong?

Other:

echo $PYTHONPATH /usr/local/lib/python2.7

dpkg -l python-numpy...

Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-===============================================-============================-============================-==================================================================================================== ii python-numpy 1:1.8.2-2 amd64 Numerical Python adds a fast array facility to the Python language 

Python 2.7.10

['', '/usr/local/lib/python2.7', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] 

which -a python...

/usr/local/bin/python /usr/bin/python 

echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
3
  • Please also add the the output of which -a python and echo $PATH. Note that apt is not installing into /usr/local, so this cannot work. Commented Sep 20, 2015 at 12:45
  • your apt-get is installing for /usr/bin/python i.e the system python, you are most likely using /usr/local/bin/python, why don't you want to use pip? Commented Sep 20, 2015 at 13:39
  • You could try apt-get source install python-numpy in /usr/local/lib/python2.7/site-packages/ then try to change the target directory and install, you could of course just use your system python but that could lead to problems Commented Sep 20, 2015 at 13:43

1 Answer 1

3

As you can tell from your which result, the python you are running when just typing python is /usr/local/bin/python.

It's a python you probably installed there yourself, as Debian will never put anything in /usr/local by itself (except for empty directories).

How? Well, by running pip for instance. As a rule, you should never use pip outside of a virtualenv, because it will install stuff on your system that your package manager will not know about. And maybe break stuff, like what you see on your system.

So, if you run /usr/bin/python, it should see the numpy package you installed using your package manager.

How to fix it? Well, I would clear anything in /usr/local (beware, it will definitely break stuff that rely on things you installed locally). Then I would apt-get install python-virtualenv, and always work with a virtualenv.

$ virtualenv -p /usr/bin/python env $ . env/bin/activate (env)$ pip install numpy (env)$ python >>> import numpy >>> 

That way, packages will be installed in the env directory. You do all this as a regular user, not root. And your different projects can have different environments with different packages installed.

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

2 Comments

Thanks for the reply :) I don't want to use pip to instal these packages as they have to build as these instances spin up and down this all adds lot of time. Also I'm a big fan of virtualenv but we don't use it in production for many reasons.
You may backup the virtualenv and restore it to avoid recompiling. As long as you don't move it, it will work transparently. Another alternative would be to make debian packages out of your projects, so they leverage Debian's dependency handling.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.