简体   繁体   English

安装的Python模块 - Python无法找到它们

[英]Installed Python Modules - Python can't find them

This is a beginner python installation question. 这是一个初学的python安装问题。 This the first time I have tried to install and call a package. 这是我第一次尝试安装和调用包。 I've got pip installed, and I tried to install two modules - numpy and pandas . 我已经安装了pip ,我试图安装两个模块 - numpypandas

In terminal, I ran the following commands: 在终端中,我运行了以下命令:

sudo pip install numpy

sudo pip install pandas

Both commands returned with a success message. 两个命令都返回成功消息。 Here is the pandas success message (it's the second package I installed and was still in my terminal history): 这是pandas成功消息(它是我安装的第二个包,仍然在我的终端历史记录中):

Successfully installed pandas
Cleaning up...

pip returned a similar message after numpy was installed. 安装numpy后, pip返回了类似的消息。

Now, when I launch python and try to call it with: 现在,当我启动python并尝试调用它时:

import pandas

I get this error message: 我收到此错误消息:

 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pandas 

Same when I try numpy . 当我尝试numpy

Can anyone tell me what I'm doing incorrectly? 谁能告诉我我做错了什么?

argh. 哎呀。 you've got two pythons in your path that are the same version? 你的路径中有两个相同版本的蟒蛇? don't do that. 不要那样做。

pip, easy-install, etc are associated with a particular python install and will use that python by default. pip,easy-install等与特定的python安装相关联,默认情况下将使用该python。 so if you have a system-provided python and a system-provided easy_install (or installed easy_install yourself using the system python) then easy_install will, by default, install packages for the system python. 所以如果你有一个系统提供的python和一个系统提供的easy_install(或者你自己使用系统python安装easy_install),那么easy_install默认会安装系统python的包。

the best way to avoid this mess, imho, is to use use system python for that version (2.7 probably) and, for other versions, use make alt-install when installing, which will give you executables like python3.1 and the like. 避免这种混乱的最好的方法,imho,是使用系统python用于该版本(可能是2.7),对于其他版本, make alt-install时使用make alt-install ,这将为您提供python3.1之类的可执行文件。 if you really need to replace the version provided by the system, uninstall it. 如果您确实需要更换系统提供的版本,请将其卸载。

once you've done that. 一旦你做完了。 each python will have a distinct name (ending in the version) and python will remain the system one. 每个python都有一个不同的名称(以版本结尾), python仍然是系统之一。

next, when you install easy_install, you'll notice that there are version-specific versions ( easy_install-2.7 for example). 接下来,当您安装easy_install时,您会注意到版本特定的版本(例如easy_install-2.7 )。 use those. 用那些。 if one is missing, then install distutils with the appropriate python (eg use python3.1 and you'll get an easy_install-3.1 ). 如果缺少一个,那么使用适当的python安装distutils(例如使用python3.1 ,你将得到一个easy_install-3.1 )。 unfortunately, each time you do this (iirc) you overwrite the un-versioned easy_install , so never use that - always use the versioned one. 不幸的是,每次你这样做(iirc)你都会覆盖未版本化的easy_install ,所以永远不要使用它 - 总是使用版本化的。

alternatively, you could not install easy_install or pip for anything other than the system version, then always use virtualenv . 或者,你不能安装easy_install或pip用于系统版本以外的任何东西,然后总是使用virtualenv virtualenv will let you specify a python version (so you can use the system virtualenv for all pythons installed) and then installs easy_install/pip for the python you use. virtualenv将允许你指定一个python版本(所以你可以使用系统virtualenv安装所有的pythons),然后为你使用的python安装easy_install / pip。 so once you're inside the virtual environment, everything just works. 所以,一旦你进入虚拟环境,一切正常。

and i just realised i haven't much experience with pip, so i can't actually help with that (except to note that virtualenv does provide it) (about which is preferable: it used to be that pip was better maintained; i think these days the latest distutils/easy_install is as good as pip, but pip has a few more features that i have never used). 我刚刚意识到我对pip没有多少经验,所以我实际上无法帮助(除了要注意virtualenv确实提供了它)(关于哪个更好:它曾经是那个pip得到了更好的维护;我认为这些天最新的distutils / easy_install和pip一样好,但是pip还有一些我从未使用过的功能。

disclaimer: the above is from experience gained developing lepl, which runs on 2.6 to 3.2, so i need to test it on all those. 免责声明:以上是从开发lepl的经验中获得的,它运行在2.6到3.2之间,因此我需要对所有这些进行测试。 as far as i know, what i describe above works for me, but i have no deep knowledge of python/easy_install/pip so i may have some mistakes in rationalising/describing things (in other words, i'm writing all this in case it helps, but i'm a bit worried i have an error - please, someone correct me if so). 据我所知,我上面描述的内容对我有用,但我对python / easy_install / pip没有深入的了解,所以我可能在合理化/描述事情时会有一些错误(换句话说,我正在写这些以防万一)它有帮助,但我有点担心我有一个错误 - 请有人纠正我,如果是这样)。

With this, I solve the problem (may help you): 有了这个,我解决了问题(可能对你有帮助):

$ sudo apt-get install python-pandas
$ sudo apt-get install python-numpy

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

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