本文介绍了Debian 没有名为 numpy 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Debian 上安装了 Python Numpy,使用...

apt-get install python-numpy

但是当运行 Python shell 时,我得到以下...

Python 2.7.10(默认,2015 年 9 月 9 日,20:21:51)[GCC 4.9.2] 在 linux2 上输入帮助"、版权"、信用"或许可"以获取更多信息.>>>导入 numpy回溯(最近一次通话最后):<module> 中的文件<stdin>"第 1 行ImportError:没有名为 numpy 的模块

当我查看 /usr/local/lib/python2.7/site-packages/ 的内容时,我注意到 numpy 不在列表中.

如果我通过 pip 安装它,即 pip install numpy 它工作得很好,但是,我想使用 apt-get 方法.我做错了什么?

其他:

回显 $PYTHONPATH/usr/local/lib/python2.7

dpkg -l python-numpy...

Desired=Unknown/Install/Remove/Purge/Hold|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend|/Err?=(none)/Reinst-required (Status,Err: uppercase=bad)||/名称 版本 架构 描述+++-================================================-=============================-============================-=======================================================================================================ii python-numpy 1:1.8.2-2 amd64 Numerical Python 为 Python 语言添加了快速数组工具

Python 2.7.10

['', '/usr/local/lib/python2.7', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/plat-linux2'、'/usr/local/lib/python2.7/lib-tk'、'/usr/local/lib/python2.7/lib-old'、'/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

which -a python...

/usr/local/bin/python/usr/bin/python

回显 $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
解决方案

从你的 which 结果可以看出,你在输入 python 时运行的 python 是/usr/local/bin/python.

这是一个你可能自己安装在那里的 python,如 Debian 永远不会单独在 /usr/local 中放置任何内容(空目录除外).

怎么样?好吧,例如通过运行 pip .作为一项规则,你不应该在 pip>virtualenv,因为它会在你的系统上安装你的包管理器不知道的东西.并且可能会破坏一些东西,比如你在系统上看到的东西.

所以,如果你运行 /usr/bin/python,它应该会看到你使用包管理器安装的 numpy 包.

如何解决?好吧,我会清除 /usr/local 中的任何内容(请注意,它肯定会破坏依赖于您在本地安装的东西的东西).然后我会 apt-get install python-virtualenv,并且总是使用 virtualenv.

$ virtualenv -p/usr/bin/python env$ .环境/bin/激活(env)$ pip install numpy(env)$ 蟒蛇>>>导入 numpy>>>

这样,包将被安装在 env 目录中.您以普通用户而不是 root 身份执行所有这些操作.而且你的不同项目可以有不同的环境,安装不同的包.

I've installed Python Numpy on Debian using...

But when run the Python shell I get the following...

Python 2.7.10 (default, Sep  9 2015, 20:21:51)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

When I view the contents of /usr/local/lib/python2.7/site-packages/ I noticed numpy is not list.

If I install it via pip i.e pip install numpy it works just fine, However, I want to use the apt-get method. What I'm I doing wrong?

Other:

dpkg -l python-numpy...

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                            Version                      Architecture                 Description
+++-===============================================-============================-============================-====================================================================================================
ii  python-numpy                                    1:1.8.2-2                    amd64                        Numerical Python adds a fast array facility to the Python language
['', '/usr/local/lib/python2.7', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

which -a python...

/usr/local/bin/python
/usr/bin/python

echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
解决方案

As you can tell from your which result, the python you are running when just typing python is /usr/local/bin/python.

It's a python you probably installed there yourself, as Debian will never put anything in /usr/local by itself (except for empty directories).

How? Well, by running pip for instance. As a rule, you should never use pip outside of a virtualenv, because it will install stuff on your system that your package manager will not know about. And maybe break stuff, like what you see on your system.

So, if you run /usr/bin/python, it should see the numpy package you installed using your package manager.

How to fix it? Well, I would clear anything in /usr/local (beware, it will definitely break stuff that rely on things you installed locally). Then I would apt-get install python-virtualenv, and always work with a virtualenv.

$ virtualenv -p /usr/bin/python env
$ . env/bin/activate
(env)$ pip install numpy
(env)$ python
>>> import numpy
>>>

That way, packages will be installed in the env directory. You do all this as a regular user, not root. And your different projects can have different environments with different packages installed.

这篇关于Debian 没有名为 numpy 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:57
查看更多