Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install numpy in a virtualenv on Debian?

(NB: see this other post for why I am not using dpkg/apt-get/etc. for this installation.)

I can install numpy in a virtualenv on Debian with, e.g., pip:

(base)[1778]% pip -v install numpy
Downloading/unpacking numpy
 ...
<output omitted>
 ...
Successfully installed numpy
Cleaning up...
  Removing temporary dir /home/jones/.virtualenvs/base/build...

But immediately after this:

(base)[1779]% python
Python 2.7.1 (r271:86832, Jun 22 2011, 15:39:05)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> ^D

Any ideas?

like image 456
kjo Avatar asked Feb 23 '23 19:02

kjo


2 Answers

I'm guessing that your virtualenv is not actually active?

You might also run into problems with this bug: https://bugs.launchpad.net/ubuntu/+source/python-virtualenv/+bug/780220

There is a similar question here: Windows + virtualenv + pip + NumPy (problems when installing NumPy) perhaps some of the answers there may help you.

like image 37
so12311 Avatar answered Mar 08 '23 13:03

so12311


OK, I found the problem. It turns out that, even though my virtualenv is active (see the (base) prefix to the command-line prompts in the screen interaction snippets above), I still need to tell pip to use it. E.g. after running something like

pip -E /path/to/virtualenv install numpy

then importing numpy within an interactive python session succeeds (whether the imported module is functional, I don't know yet).

This is absurd: my virtualenv is active, and the pip executable I'm running is the one installed in that virtualenv:

(base)[1801] which pip
/home/jones/.virtualenvs/base/bin/pip

So what's the point of having a virtualenv if pip will not use it by default???

like image 140
kjo Avatar answered Mar 08 '23 13:03

kjo