我安装了 Python 2.7 和 3.5。如果我使用 python
从命令行运行脚本,它会使用 Python 2.7,但如果我启动 iPython,它会使用 Python 3:
kurt@kurt-ThinkPad:~$ python -V
Python 2.7.12
kurt@kurt-ThinkPad:~$ ipython
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.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 以便它使用 Python 2? (我使用的是 Ubuntu LTS 16.04)。
最佳答案
此问题的侵入性较小的解决方案(因为我下面的解决方案不需要更改任何库文件)是
python2.7 -m IPython notebook
所以一般命令是
{{python-you-want-ipython-to-use}} -m IPython 笔记本
为什么这会起作用?
因为如果你看到 ipython script (/usr/local/bin/ipython) 它本身似乎是一个 python 脚本,并且它有 shebang (#!/usr/bin/python3),所以 ipython 不是一个独立的二进制文件,但它得到生命是因为一些 python 。因此,由于 ipython 脚本本身需要一些 python 来运行它,因此您可以直接使用您选择的某些 python 运行 ipython 模块,而不是让/usr/local/bin/ipython 为您决定它,这就是修复“python ipython 使用什么”的问题。
关于python-2.7 - 如何让 iPython 使用 Python 2 而不是 Python 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40419609/