本文介绍了如何让iPython使用Python 2而不是Python 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了Python 2.7和3.5。如果我使用 python 从命令行运行脚本,它使用Python 2.7,但是如果我启动iPython,它使用Python 3:

I have both Python 2.7 and 3.5 installed. If I run a script from the command line using python, it uses Python 2.7, but if I launch iPython, it uses 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)。

Is there a way to launch iPython so that it uses Python 2? (I'm using Ubuntu LTS 16.04).

推荐答案

关注,在 / usr / local / bin / ipython 中,我只需更改

Following ipython reads wrong python version, in /usr/local/bin/ipython, I simply changed

#!/usr/bin/python3

第一行

#!/usr/bin/python

并且Python 2已成为iPython使用的默认版本:

and Python 2 has become the default version used by iPython:

kurt@kurt-ThinkPad:~$ ipython
Python 2.7.12 (default, Jul  1 2016, 15:12:24)
Type "copyright", "credits" or "license" for more information.

IPython 2.4.1 -- 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.

这篇关于如何让iPython使用Python 2而不是Python 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:18