简体   繁体   English

Debian No Module名为numpy

[英]Debian No Module named numpy

I've installed Python Numpy on Debian using... 我已经使用...在Debian上安装了Python Numpy

apt-get install python-numpy apt-get安装python-numpy

But when run the Python shell I get the following... 但是当运行Python shell时,我得到以下信息...

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. 当我查看/usr/local/lib/python2.7/site-packages/的内容时,我发现numpy没有列出。

If I install it via pip ie pip install numpy it works just fine, However, I want to use the apt-get method. 如果我通过pip安装它,即pip install numpy它就可以正常工作,但是,我想使用apt-get方法。 What I'm I doing wrong? 我做错了什么?

Other: 其他:

echo $PYTHONPATH /usr/local/lib/python2.7 回声$ PYTHONPATH /usr/local/lib/python2.7

dpkg -l python-numpy... 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

Python 2.7.10 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... 哪个-python ...

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

echo $PATH 回声$ 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 . 你可以从你告诉which的结果,你正在运行时,只输入蟒python/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). 这可能是您自己安装的python,因为Debian绝不会将任何东西单独放在/usr/local (空目录除外)。

How? 怎么样? Well, by running pip for instance. 好吧,例如,通过运行pip 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. 通常,永远不要在virtualenv之外使用pip ,因为它将在软件包管理器不知道的系统上安装东西。 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. 因此,如果您运行/usr/bin/python ,它将看到使用软件包管理器安装的numpy软件包。

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). 好吧,我会清除/usr/local (请注意,它肯定会破坏依赖于本地安装的内容的内容)。 Then I would apt-get install python-virtualenv , and always work with a virtualenv. 然后,我将apt-get install python-virtualenv ,并始终与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. 这样,程序包将安装在env目录中。 You do all this as a regular user, not root. 您以普通用户(而不是root用户)身份执行所有操作。 And your different projects can have different environments with different packages installed. 您的不同项目可以具有安装了不同软件包的不同环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM