已安装的Python模块-Python找不到它们

问题描述:

这是初学者python安装问题.这是我第一次尝试安装并调用软件包.我已经安装了pip,并且尝试安装两个模块-numpypandas.

This is a beginner python installation question. 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.

在终端中,我运行了以下命令:

In terminal, I ran the following commands:

sudo pip install numpy

sudo pip install pandas

两个命令均返回成功消息.这是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):

Successfully installed pandas
Cleaning up...

安装numpy后,

pip返回了类似的消息.

pip returned a similar message after numpy was installed.

现在,当我启动python并尝试通过以下方式调用它时:

Now, when I launch python and try to call it with:

import pandas

我收到此错误消息:

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

与我尝试numpy时相同.

谁能告诉我我做错了什么?

Can anyone tell me what I'm doing incorrectly?

argh.您的路径中有两个版本相同的python吗?不要那样做.

argh. you've got two pythons in your path that are the same version? don't do that.

pip,易安装等与特定的python安装相关,默认情况下将使用该python.因此,如果您具有系统提供的python和系统提供的easy_install(或使用系统python自己安装了easy_install),则easy_install将默认为系统python安装软件包.

pip, easy-install, etc are associated with a particular python install and will use that python by default. 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(可能是2.7),而其他版本则在安装时使用make alt-install,这将为您提供可执行文件,例如python3.1和喜欢.如果您确实需要替换系统提供的版本,请卸载它.

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. if you really need to replace the version provided by the system, uninstall it.

完成此操作.每个python都有一个唯一的名称(以版本结尾),python将保持系统名称不变.

once you've done that. each python will have a distinct name (ending in the version) and python will remain the system one.

接下来,当您安装easy_install时,您会注意到存在特定于版本的版本(例如easy_install-2.7).用那些.如果缺少,则使用适当的python安装distutils(例如,使用python3.1,您会得到一个easy_install-3.1).不幸的是,每次执行此操作(iirc)时,您都会覆盖未版本化的easy_install,因此从不使用它-始终使用版本控制的版本.

next, when you install easy_install, you'll notice that there are version-specific versions (easy_install-2.7 for example). 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). unfortunately, each time you do this (iirc) you overwrite the un-versioned easy_install, so never use that - always use the versioned one.

或者,您无法为系统版本以外的任何版本安装easy_install或pip,然后始终使用virtualenv . virtualenv将允许您指定一个python版本(因此您可以将系统virtualenv用于所有已安装的python),然后为您使用的python安装easy_install/pip.因此,一旦进入虚拟环境,一切都将正常工作.

alternatively, you could not install easy_install or pip for anything other than the system version, then always use 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. so once you're inside the virtual environment, everything just works.

,我刚刚意识到我对pip的经验不足,所以我实际上无法提供帮助(除非要注意virtualenv确实提供了pip)(最好是这样:以前是因为pip维护得更好) ;我认为这些天最新的distutils/easy_install与pip一样好,但是pip具有一些我从未使用过的功能).

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).

免责声明:以上内容是从开发lepl(在2.6到3.2上运行)获得的经验得出的,因此我需要对所有这些进行测试.据我所知,我上面描述的内容对我有用,但是我对python/easy_install/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. 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).