pandas 导入熊猫导入错误:没有名为熊猫的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24795665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:16:10  来源:igfitidea点击:

import pandas ImportError: No module named pandas

pythonpandas

提问by user3847638

When I try to run the following source (I installed anaconda, there is no problem with other anaconda libraries ):

当我尝试运行以下源时(我安装了anaconda,其他anaconda库没有问题):

#!/usr/bin/python 

import pandas

def add_full_name(path_to_csv, path_to_new_csv):
    f = pandas.read_csv(path_to_csv)
    print f['nameFirst'], f['nameLast']
    f['nameFull'] = f['nameFirst'] + ' ' + f['nameLast']
    f.to_csv(path_to_new_csv)

add_full_name("./AllstarFull.csv", "./AllstarFullNew.csv")
#!/usr/bin/python 

import pandas

def add_full_name(path_to_csv, path_to_new_csv):
    f = pandas.read_csv(path_to_csv)
    print f['nameFirst'], f['nameLast']
    f['nameFull'] = f['nameFirst'] + ' ' + f['nameLast']
    f.to_csv(path_to_new_csv)

add_full_name("./AllstarFull.csv", "./AllstarFullNew.csv")

I get

我得到

"import pandas
 ImportError: No module named pandas"

But when I used the command line and did import panda there where no problem

但是当我使用命令行并在那里导入Pandas时没有问题

$ python
Python 2.7.8 |Anaconda 2.0.0 (x86_64)| (default, Jul  2 2014, 15:36:00) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import pandas
>>>

But I still can't use any command of pandas I like to

但是我仍然不能使用我喜欢的任何Pandas命令

回答by Oleg Gryb

If you want to have the same result for running it from interpreter and through "./prog.py", make sure that you have the following in your Python module instead of #!/usr/bin/python:

如果你想从解释器运行它并通过“./prog.py”获得相同的结果,请确保你的 Python 模块中有以下内容而不是 #!/usr/bin/python:

#!<path-to-your-anacaonda-python>

The 'which' command that I was writing about will provide the path

我正在写的“which”命令将提供路径

回答by holdenweb

Your program specifically asks to run the system Python with the shebang line #!/usr/bin/python, so whether you have installed anaconda or not this program won't run using anaconda's Python. Try running the command

您的程序特别要求使用 shebang 行运行系统 Python #!/usr/bin/python,因此无论您是否安装了 anaconda,该程序都不会使用 anaconda 的 Python 运行。尝试运行命令

python program.py

(or whatever your program is called). That should ensure that you get the version of Python with Pandas installed in it.

(或者无论你的程序叫什么)。这应该确保您获得安装了 Pandas 的 Python 版本。

回答by Yinhui

I met this same issue when setting up the anaconda along with ST3, and got it fixed by: file->preference->browse packages. Then go to user and open Python3.sublime-build, edit the cmd with the python from anaconda. Restart and enjoy.

我在设置 anaconda 和 ST3 时遇到了同样的问题,并通过以下方式修复:文件->首选项->浏览包。然后转到用户并打开 Python3.sublime-build,使用 anaconda 中的 python 编辑 cmd。重新开始并享受。

{
 "cmd": ["/Users/*USERNAME*/anaconda/bin/python", "-u", "$file"],
 "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
 "selector": "source.python" 
}