iPython 已安装但未找到

iPython installed but not found

我最近删除了 Anaconda 并使用 brew 重新安装了 python。我已经根据 these 说明安装了所有内容。

Python 效果很好,到目前为止我测试过的所有包也都可以。我已经安装了 ipython,但尝试从终端启动它会得到:

-bash: ipython: command not found

我将安装定位在:

/usr/local/lib/python2.7/site-packages/ipython

根据较早的相关问题,我尝试将此路径添加到 .bash_profile 但得到:

-bash: :/usr/local/lib/python2.7/site-packages/ipython: No such file or directory

每当终端启动时。

更多信息:Anaconda 安装了一个已删除的 El-Capitan 10.11.2、python 2.7.

如有任何帮助,我们将不胜感激!

编辑:向@cel 请求添加了更多信息:

echo $PATH 给出:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Library/TeX/texbin:/Applications/Sublime Text.app/Contents/SharedSupport/bin

which -a python 给出: /usr/local/bin/python/usr/bin/python.

编辑:将 python -m pip install ipython 的输出添加到 cel 的请求中:

Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): traitlets in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): decorator in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): gnureadline in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): appnope in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pexpect in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): ipython-genutils in /usr/local/lib/python2.7/site-packages (from traitlets->ipython)
Requirement already satisfied (use --upgrade to upgrade): path.py in /usr/local/lib/python2.7/site-packages (from pickleshare->ipython)
Requirement already satisfied (use --upgrade to upgrade): ptyprocess>=0.5 in /usr/local/lib/python2.7/site-packages (from pexpect->ipython)

在网络上搜索 "bash: ipython: command not found" 会出现几个结果(包括 this SO question),但它们并不是特别有用。从它的声音来看,您已经安装了 IPython、Python 软件包 ,但是 ipython 入口点 (即 wrapper/launcher 脚本)——无论出于何种原因都丢失了。要检查是否是这种情况,请尝试 运行:

% python -m IPython
Python 2.7.9 (default, Feb 10 2015, 03:28:08) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

如果出现 IPython,那么您可以尝试制作一个 shell 别名,正如上面链接的 SO 答案所建议的那样,即在您的 shell 中添加这样的内容启动脚本:alias ipython='python -m IPython'。或者,您自己创建启动器脚本。对我来说,它位于 /usr/local/bin/ipython 并包含以下内容:

#!/usr/local/opt/python/bin/python2.7

# -*- coding: utf-8 -*-
import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

希望这对您有所帮助。 (如果是,请考虑对另一个 SO 问题 投赞成票...)

更新:这里有一些更可能相关的链接:

@evadeflow 给出的答案可以完成工作,但是还有其他几个安装了 pip 的软件包,为每个软件包添加 alias 会很不舒服。 一种相当优雅的方法是将安装这些软件包的路径添加到 $PATH 变量中。在我的例子中,在 ~/.bashrc 中添加以下行就完成了工作:

export PATH=$PATH:/home/my_user_name/.local/bin

添加参考:https://askubuntu.com/q/551990/632996; https://askubuntu.com/q/556090

我在 Ubuntu 18.04 中使用 apt 安装了 ipython,如下所示:

sudo apt install python-ipython

然后,'ipython' 命令不起作用,我得到了与上述相同的“未找到命令”错误。安装 python3-python 后也是如此。但是,然后我尝试 sudo apt install ipython 并安装了正确的包装器。我不知道 pip 是否会发生类似的事情,但这是我使用 apt 的经验。

有时您只需要在成功安装 anaconda 后获取您的 bash_profile。

source ~/.bash_profile

对我有用的是卸载使用:

~pip3 uninstall ipython

然后:

~sudo pip3 install ipython

我 运行 在 (W10)WSL2 上使用 Debian。

如果使用 Python3,只需尝试:

ipython3

对我有用。

对于 anaconda 用户:

conda install -c conda-forge ipywidgets

对于python3

python3 -m IPython