如何在 Debian 上的 virtualenv 中安装 numpy?
(注意:请参阅这篇文章解释了为什么我没有使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,我发现问题了。事实证明,即使我的 virtualenv 处于活动状态(请参阅上面屏幕交互片段中命令行提示的
(base)
前缀),我仍然需要告诉 pip 使用它。例如,在交互式 python 会话中运行类似的命令后,导入 numpy 会成功(导入的模块是否有效,我还不知道)。
这是荒谬的:我的 virtualenv 处于活动状态,而我正在运行的 pip 可执行文件是安装在该 virtualenv 中的可执行文件:
那么,如果 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 likethen 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:
So what's the point of having a virtualenv if pip will not use it by default???
我猜你的 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.
关于命令的最后一个错误:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
这是该问题的解决方案。
升级到最新的 virtualenv:
创建你的 python virtualenv 并运行
问候,Karlo。
regarding the last error for command:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Here is solution to that problem.
Upgrade to latest virtualenv:
create your python virtualenv and run
Regards, Karlo.