在Mac OSX中将内核更改为另一个版本的python而不是系统Python

时间:2016-03-31 12:51:06

标签: python ipython jupyter jupyter-notebook

我已经通过HomeBrew安装了Python,如下所示:

J-MBP:runtime my$ ll `which python`
lrwxr-xr-x  1 my  admin  34 Mar 31 14:20 /usr/local/bin/python -> ../Cellar/python/2.7.11/bin/python
J-MBP:runtime my$ python
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'2.7.11 (default, Jan 22 2016, 08:29:18) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]'

但是,当我运行jupyter notebook并仔细检查python版本时,它仍然使用系统上预安装的旧版本。

import sys
sys.version

Out[3]:  '2.7.10 (default, Oct 23 2015, 18:05:06) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]'

我想知道如何将python更改为Jupyter Notebook中新安装的python。

2 个答案:

答案 0 :(得分:2)

ipython kernel install,检查当前内核路径。 cd然后vim kernel.json

{
 "display_name": "Python 2",
 "language": "python",
 "argv": [
  "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
 ]
}

argv 参数更改为新安装的python路径将解决问题。

答案 1 :(得分:0)

您可以输入which jupiter并编辑该文件。我想从自制软件安装的先前版本在该文件的shebang行中被硬编码到which python返回的路径