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

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

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

pip returned a similar message after numpy was installed.

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

import pandas

I get this error message:

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named pandas

Same when I try 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. 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.

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.

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

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.

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.

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值