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

Change kernel to another version of python instead of system Python in Mac OSX

我已经通过 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 中新安装的

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

的路径

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 路径将解决问题。