开发者

How to install numpy in a virtualenv on Debian?

开发者 https://www.devze.com 2023-03-15 07:49 出处:网络
(NB: see this other p开发者_开发问答ost for why I am not using dpkg/apt-get/etc. for this installation.)

(NB: see this other p开发者_开发问答ost 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?


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号