如何在 Debian 上的 virtualenv 中安装 numpy?

发布于 2024-11-17 01:41:20 字数 876 浏览 4 评论 0原文

(注意:请参阅这篇文章解释了为什么我没有使用 dpkg/apt-get/etc 来进行安装。)

我可以使用 pip 在 Debian 上的 virtualenv 中安装 numpy:

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

但是紧接着:

(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

有什么想法吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

计㈡愣 2024-11-24 01:41:20

好的,我发现问题了。事实证明,即使我的 virtualenv 处于活动状态(请参阅上面屏幕交互片段中命令行提示的 (base) 前缀),我仍然需要告诉 pip 使用它。例如,在交互式 python 会话中运行类似的命令后

pip -E /path/to/virtualenv install numpy

,导入 numpy 会成功(导入的模块是否有效,我还不知道)。

这是荒谬的:我的 virtualenv 处于活动状态,而我正在运行的 pip 可执行文件是安装在该 virtualenv 中的可执行文件:

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

那么,如果 pip 默认情况下不使用 virtualenv,那它还有什么意义呢? ?

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

守护在此方 2024-11-24 01:41:20

我猜你的 virtualenv 实际上并没有处于活动状态?

您可能还会遇到此错误的问题: https:// bugs.launchpad.net/ubuntu/+source/python-virtualenv/+bug/780220

这里有一个类似的问题:Windows + virtualenv + pip + NumPy(安装 NumPy 时出现问题)
也许那里的一些答案可能对您有帮助。

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.

时常饿 2024-11-24 01:41:20

关于命令的最后一个错误:

pip -E /path/to/virtualenv install numpy

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

这是该问题的解决方案。

升级到最新的 virtualenv:

sudo pip install --upgrade virtualenv

创建你的 python virtualenv 并运行

pip -E /path/to/virtualenv install numpy

问候,Karlo。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文