4

(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?

Community
  • 1
  • 1
kjo
  • 33,683
  • 52
  • 148
  • 265

3 Answers3

5

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???

kjo
  • 33,683
  • 52
  • 148
  • 265
  • 2
    There is no -E option in 1.5 version and the way to install it $ /home$USER/.."path to virtualenv/ENV"./virtualenv/ENV/bin/pip install numpy – Medhat Jan 15 '15 at 13:11
  • 1
    This drove me crazy and makes no sense why it would only affect pandas/numpy but not other packages. – wrschneider Jan 10 '19 at 20:46
3

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.

Community
  • 1
  • 1
so12311
  • 4,179
  • 1
  • 29
  • 37
0

regarding the last error for command:

pip -E /path/to/virtualenv install numpy

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Here is solution to that problem.

Upgrade to latest virtualenv:

sudo pip install --upgrade virtualenv

create your python virtualenv and run

pip -E /path/to/virtualenv install numpy

Regards, Karlo.

Karlo Smid
  • 525
  • 1
  • 5
  • 13