Pandas 模块:适用于 PyCharm 但不适用于终端

Pandas Module: Works in PyCharm but not Terminal

我在 PyCharm 中编写了一个依赖于 pandas 模块的 python 脚本(称为 python_script.py)。问题是,当我 运行 PyCharm 中的脚本时,它工作得很好。但是当我在终端中调用它时,出现以下错误:

Traceback (most recent call last):
File "./sub_directory/python_script.py", line 9, in <module>
import pandas
ImportError: No module named pandas

您可以通过在终端执行 conda install pandas 将 pandas 安装到您的 anaconda 安装中。这可能是最简单的解决方案,但您也可以像这样使用其他 Python 安装:

/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents‌​/MacOS/Python python_script.py

您还可以在您的终端中创建一个别名,这样 python 将指向系统 python 安装。为此,您可以将行

alias python=/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents‌​/MacOS/Python

在你的 ~/.bash_profile

(供参考:http://www.moncefbelyamani.com/create-aliases-in-bash-profile-to-assign-shortcuts-for-common-terminal-commands/