IPython笔记本,如何设置正确的内核路径?

4
在Windows 7 64位系统上运行ipython笔记本并使用Python 2内核启动笔记本时,出现错误:
Traceback (most recent call last):
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\base\handlers.py", line 436, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\services\sessions\handlers.py", line 56, in post
    model = sm.create_session(path=path, kernel_name=kernel_name)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 66, in create_session
    kernel_name=kernel_name)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 84, in start_kernel
    **kwargs)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\multikernelmanager.py", line 109, in start_kernel
    km.start_kernel(**kwargs)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 244, in start_kernel
    **kw)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 190, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\launcher.py", line 115, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\Users\USER1\Anaconda2\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Users\USER1\Anaconda2\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

我进一步调查了这个问题,并在launcher.py文件中的proc = Popen(cmd, **kwargs)之前添加了以下打印行:

    print cmd
    print kwargs

现在我看到proc = Popen(cmd, **kwargs)是使用cmd=调用的

['C:\\Users\\USER1\\Anaconda2_32bit\\python.exe', '-m', 'ipykernel', '-f', '
C:\\Users\\USER1\\AppData\\Roaming\\jupyter\\runtime\\kernel-a3f46334-4491-4
fef-aeb1-6772b8392954.json']

这是一个问题,因为我的python.exe不在这里。
C:\\Users\\USER1\\Anaconda2_32bit\\python.exe

but in

C:\\Users\\USER1\\Anaconda2\\python.exe

然而,我已经在“计算机/高级系统设置/高级/环境变量”中检查了路径,从未指定\\Anaconda2_32bit\\

因此,我怀疑虚假路径在其他地方被指定。它可能在哪里?我该如何修复它?

另外,我以前安装过Anaconda在\\Anaconda2_32bit\\,但我已经卸载了它。

1个回答

11

IPython有内核注册在特殊的配置文件中。 我运行了命令:

ipython kernelspec list

输出结果如下:

Available kernels:
  python2    C:\ProgramData\jupyter\kernels\python2

我查看了 C:\ProgramData\jupyter\kernels\python2\kernel.json 文件,发现设置了错误的 Python2 路径。我已经修复了路径,现在它可以正常工作。


随着ipython命令的弃用,现在建议使用jupyter kernelspec list进行操作。 - whoopscheckmate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接