首页 > 解决方案 > Jupyter Notebook:连接到服务器时出错

问题描述

我刚刚安装了最新的 python 版本(3.8.5)(Anaconda发行版),同时正确执行了文档中提到的所有步骤

文档链接

然后我尝试使用以下方法将其添加到我的 Jupyter Notebook 中:

python -m ipykernel install --user --name=Python3.8.5

【Python3.8.5为环境名称】

我成功将它添加到了jupyter notebook中!

但是当我尝试使用 Jupyter Notebook 访问它时,这就是它所显示的内容: 这里: jupyter notebook 命令行中的回溯如下:

    To access the notebook, open this file in a browser:
        file:///C:/Users/aakash/AppData/Roaming/jupyter/runtime/nbserver-5272-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=53898b31bc28a966e6576d5e20099d192dc5c95ddff14a4c
     or http://127.0.0.1:8888/?token=53898b31bc28a966e6576d5e20099d192dc5c95ddff14a4c
[I 16:56:48.967 NotebookApp] Creating new notebook in
[I 16:56:57.277 NotebookApp] Kernel started: 09f6bfbd-6e88-4264-a4a3-c975801012bc, name: python3.8.5
Traceback (most recent call last):
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\traitlets\config\application.py", line 836, in launch_instance
    app.initialize(argv)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\traitlets\config\application.py", line 86, in inner
    return method(app, *args, **kwargs)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 570, in initialize
    self.write_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 230, in write_connection_file
    write_connection_file(cf, ip=self.ip, key=self.session.key, transport=self.transport,
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 138, in write_connection_file
    with secure_write(fname) as f:
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_core\paths.py", line 435, in secure_write
    win32_restrict_file_to_user(fname)
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_core\paths.py", line 361, in win32_restrict_file_to_user
    import win32api
ImportError: DLL load failed while importing win32api: The specified module could not be found.
[I 16:57:00.140 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 16:57:03.144 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 16:57:06.150 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[I 16:57:09.159 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
[IPKernelApp] ERROR | Failed to load connection file: 'C:\\Users\\aakash\\AppData\\Roaming\\jupyter\\runtime\\kernel-09f6bfbd-6e88-4264-a4a3-c975801012bc.json'
Traceback (most recent call last):
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 257, in init_connection_file
    self.load_connection_file()
  File "C:\Users\aakash\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 496, in load_connection_file
    info = json.load(f)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\aakash\Anaconda3\envs\Python3.8.5\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[W 16:57:12.163 NotebookApp] KernelRestarter: restart failed
[W 16:57:12.163 NotebookApp] Kernel 09f6bfbd-6e88-4264-a4a3-c975801012bc died, removing from map.
[W 16:57:57.333 NotebookApp] Timeout waiting for kernel_info reply from 09f6bfbd-6e88-4264-a4a3-c975801012bc
[E 16:57:57.333 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: 09f6bfbd-6e88-4264-a4a3-c975801012bc)
[W 16:57:58.366 NotebookApp] 404 GET /api/kernels/09f6bfbd-6e88-4264-a4a3-c975801012bc/channels?session_id=7b5b1d566bd249d981caaf4631317e38 (::1): Kernel does not exist: 09f6bfbd-6e88-4264-a4a3-c975801012bc
[W 16:57:58.400 NotebookApp] 404 GET /api/kernels/09f6bfbd-6e88-4264-a4a3-c975801012bc/channels?session_id=7b5b1d566bd249d981caaf4631317e38 (::1) 35.90ms referer=None
[W 16:58:00.426 NotebookApp] Replacing stale connection: 09f6bfbd-6e88-4264-a4a3-c975801012bc:7b5b1d566bd249d981caaf4631317e38
[I 16:58:57.356 NotebookApp] Saving file at /Untitled5.ipynb
[W 17:02:05.348 NotebookApp] Replacing stale connection: 09f6bfbd-6e88-4264-a4a3-c975801012bc:7b5b1d566bd249d981caaf4631317e38
[W 17:06:13.365 NotebookApp] Replacing stale connection: 09f6bfbd-6e88-4264-a4a3-c975801012bc:7b5b1d566bd249d981caaf4631317e38

我查看了 github 和 stackoverflow 上的所有可用解决方案,但没有一个提供明确的解决方案。请帮帮我!! [我在窗户上]

请提出必要的步骤!我急需帮助!!! 编辑:降级龙卷风、降级 conda 等解决方案不起作用!!我已经尝试更新所有软件包,即使它不起作用!

标签: pythonpython-3.xjupyter-notebookanacondavirtualenv

解决方案


如果您在 Conda 环境中,请尝试:

conda install pywin32

推荐阅读