Pandas 已安装,但找不到?这是为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27179268/
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:43:24  来源:igfitidea点击:

Pandas installed, but cannot be found? Why is that?

pythonpandas

提问by Chef1075

I have installed Anaconda, so I'm fairly sure I have installed Pandas.

我已经安装了 Anaconda,所以我很确定我已经安装了 Pandas。

However, when I run this in Sublime:

但是,当我在 Sublime 中运行它时:

import pandas as pd

I get this message:

我收到这条消息:

Traceback (most recent call last):
  File "/Users/user/Documents/Programming/Python/Python for Finance/7_4.py", line 184, in <module>
    import pandas as pd
ImportError: No module named pandas
[Finished in 0.4s with exit code 1]

But when I go to the terminal:

但是当我去终端时:

Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
>>> import pandas
>>> import pandas as pd
>>> pd.__version__
'0.15.1'

So I know I have pandas, and I've also updated anaconda to the newest version....

所以我知道我有Pandas,而且我也将 anaconda 更新到了最新版本......

Chef-3:~ user$ conda update anaconda Fetching package metadata: ..
# All requested packages already installed.
# packages in environment at /Users/user/anaconda:
# anaconda                  2.1.0                np19py27_0

So what am I missing?

那么我错过了什么?

Thanks :)

谢谢 :)

回答by brian

I ran into the same problem with PyCharm a few weeks ago. My solution, if all else fails, is to move over to iPython Notebook. Since that runs Anaconda, you know it will detect pandas successfully. For some reason (maybe the reason @DSM mentioned), sometimes installing a package on Anaconda doesn't transfer over to all of your IDEs.

几周前,我在使用 PyCharm 时遇到了同样的问题。如果所有其他方法都失败,我的解决方案是转移到 iPython Notebook。由于它运行 Anaconda,您知道它会成功检测到Pandas。出于某种原因(也许是@DSM 提到的原因),有时在 Anaconda 上安装软件包并不会转移到您的所有 IDE。

回答by Jacob Budin

Once Anaconda is installed, its Python distribution supercedes the Python distribution that ships with OS X. You've installed Pandas on the former distribution (or rather, it's come pre-installed), while Sublime Text is relying on the latter distribution to build and run.

安装 Anaconda 后,它的 Python 发行版将取代 OS X 附带的 Python 发行版。您已经在前一个发行版上安装了 Pandas(或者更确切地说,它是预装的),而 Sublime Text 依赖后一个发行版来构建和跑。

You'll want to modify Sublime Text to use the Python distribution from Anadonda. You can modify Python.sublime-settingsas shown in Sublime Text 2: custom PATH and PYTHONPATHto do this.

您需要修改 Sublime Text 以使用来自 Anadonda 的 Python 发行版。您可以Python.sublime-settings按照Sublime Text 2: custom PATH 和 PYTHONPATH 中所示进行修改来执行此操作。

(Addendum: To find where pythonis being executed from Terminal.app, you can run: $ which python.)

(附录:要从pythonTerminal.app 中查找正在执行的位置,您可以运行:$ which python。)

回答by ccpizza

Check the version of python that gets run when pandasis found, and the version when it is not found —?most likely they are not the same.

检查pandas找到时运行的python版本,以及未找到时的版本 - 很可能它们不一样。

Check the pythons you have on your system:

检查您系统上的pythons:

ls -larth `which python`*

For example one of the installed pythons is /usr/bin/python3.6— you can set it as the default for the current user by adding an alias to /.bashrc:

例如,已安装的 python 之一是/usr/bin/python3.6- 您可以通过向以下项添加别名将其设置为当前用户的默认值/.bashrc

alias python3='/usr/bin/python3.6'

Another (not recommended) approach would be changing the symlinks in /usr/bin/or /usr/local/binto the versions of python you want to use, but this can potentially break things, e.g. ubuntu uses specific versions of python with specific modules to do various system tasks.

另一个(不推荐)的做法将被改变的符号链接/usr/bin//usr/local/bin您要使用Python的版本,但这个可能会破坏东西,如Ubuntu的使用与特定模块的Python的特定版本做各种系统任务。

And lastly, review your .bashrc, .bash_profile(or the equivalents for the shell you are using if other than bash), and find all the places where $PATHand $PYTHONPATHis (re)defined — if you have changed it manually then it might be time to review it.

最后,检查你的.bashrc.bash_profile(或者等同于您使用的是否比其他的外壳bash),并找到所有的地方$PATH$PYTHONPATH是(重新)定义-如果你已经改变了它手动那么它可能是时间来它。