How to install numpy in a virtualenv on Debian?

自闭症网瘾萝莉.ら 提交于 2019-12-23 13:25:06

问题


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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6451821/how-to-install-numpy-in-a-virtualenv-on-debian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!