我们能否更改IPython使用的Python解释器版本?
我知道有IPython和IPython3,但问题是,IPython使用Python2.7,而IPython3使用Python3.4.2,我看不到任何改变的方法。
如果我想要IPython使用任何我想要的Python解释器版本,我该怎么做?
我希望IPython使用最新的Python版本,Python3.6。我能做到这点吗?
我们能否更改IPython使用的Python解释器版本?
我知道有IPython和IPython3,但问题是,IPython使用Python2.7,而IPython3使用Python3.4.2,我看不到任何改变的方法。
如果我想要IPython使用任何我想要的Python解释器版本,我该怎么做?
我希望IPython使用最新的Python版本,Python3.6。我能做到这点吗?
修改分布式文件应该是最后的选择。我建议使用 Python3.6 在 Ubuntu 17.04 上采用以下方法:
python3.6 -m pip install IPython # lots of output, make IPython available to script ipython3
python3.6 `which ipython3`
Python 3.6.1 (default, Mar 22 2017, 06:17:05)
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
看起来我找到了解决方案。
你需要编辑启动IPython的文件。在Linux上,你可以通过输入以下命令进入:sudo nano $(which ipython)
。
一旦你进入了文件,将shebang行更改为你喜欢的任何Python解释器。
而包含Python3.4模块的目录需要添加到$PYTHONPATH变量中。
什么是shebang行? 文件中的第一行代表将要使用的Python解释器路径。
感谢@code_byter。
首先,请使用which ipython
命令检查Python IPython使用的版本(版本指解释器的路径)。一旦确定了路径,请打开文件并将内容发布在此处。
尝试让它看起来像这样:
#!/usr/bin/python
# -*- 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())
第一行代码是确保使用本地的Python解释器,通常被称为 shebang 行。
如果你使用的是 Windows 系统,请尝试使用 where ipython
命令。
vim /usr/bin/ipython3
命令,找到了以下Bash脚本:#! /bin/sh
VERSION="3"
if [ ! -f /usr/bin/python$VERSION ]
then
[...]
VERSION=3
这一行更改为VERSION=3.6
。请注意,在我的电脑上将VERSION
变量设置为3.6.2
并不起作用。