帮助让 iPython 从 OSX 终端运行

帮助让 iPython 从 OSX 终端运行

得到 stackoverflow.com 的提醒,可以在这里提问。

我正在阅读 matplotlib 文档并准备使用 iPython 交互式 Python shell ipython -pylab。但是我得到了这个:

MBP:~ Me$ ipython -pylab
-bash: ipython: command not found

我安装 iPython 失败了吗?我easy_install按照建议使用。

有任何想法吗?

更新

我只是想说,/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin在进行 Spotlight 搜索后,我发现了 iPython“可执行文件”。

仍然有点困惑该做什么。

答案1

看起来你的 Python 2.6 安装已经通过麦金塔,基于/opt/local前缀。如果您没有使用 MacPorts 安装它并且有自己的使用理由/opt/local,请忽略此答案。如果您这样做了,您可以使用 安装 ipython port

port install py26-ipython

确保将$PATH环境变量设置为 include /opt/local/bin。这应该由 MacPorts 安装程序完成。我的~/.profile看起来像:

# MacPorts Installer addition on 2009-03-05_at_21:11:52: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.


# MacPorts Installer addition on 2009-03-05_at_21:11:52: adding an appropriate MANPATH variable for use with MacPorts.
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.

我会谨慎地将 easy_install 与 MacPorts python 结合使用,尤其是对于 MacPorts 已经提供的模块。例如,MacPorts ipython 将可执行文件/opt/local/bin/ipython2.6放在/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython

编辑
要卸载 easy_installed 版本的 ipython,据我所知,您需要手动删除相关文件。我根据我的 ipython 安装情况做了一些尝试。首先删除可执行文件:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipcluster
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipcontroller
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipengine
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/iptest
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython-wx
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipythonx
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/irunner
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/pycolor

然后,删除 site-packages 中的文件夹和 egg-info:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/IPython/
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ipython-0.10-py2.6.egg-info

然后,删除 doc 文件夹:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/doc/ipython/

然后,删除 man 文件:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipcluster.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipcontroller.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipengine.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipython-wx.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipython.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipythonx.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/irunner.1.gz
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/pycolor.1.gz

最后,打开文件/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/easy-install.pth并查看是否有引用 ipython egg 的行。删除它。

答案2

这听起来像是你的 PATH 出了问题。在终端中检查你的 ~/.profile 或 ~/.bashrc,并确保在 Apple 默认设置之前 /usr/local/bin 位于你的 $PATH 中。

PATH="/usr/local/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"

更多信息请点击这里:http://ipython.scipy.org/moin/Py4Science/InstallationOSX

相关内容