解决 PyCharm 无法启动 Jupyter 服务器的问题:报错分析与解决方案

报错背景

在使用 pycharm 付费版的过程中,发现一直无法启动 jupyter 服务器。
一直也不知道是为什么,直到在终端输入:

jupyter notebook

发现 jupyter 服务无法启动。

报错详细信息

下述是我运行 jupyter notebook 命令后的报错信息。

[I 2024-09-14 15:51:53.496 ServerApp] Package notebook took 0.0000s to import
[I 2024-09-14 15:51:53.499 ServerApp] Package jupyter_lsp took 0.0030s to import
[W 2024-09-14 15:51:53.499 ServerApp] A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2024-09-14 15:51:53.501 ServerApp] Package jupyter_server_terminals took 0.0013s to import
[I 2024-09-14 15:51:53.501 ServerApp] Package jupyterlab took 0.0000s to import
Fail to get yarn configuration. internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at /home/jie/anaconda3/lib/python3.11/site-packages/jupyterlab/staging/yarn.js:423:2576
    at Object.<anonymous> (/home/jie/anaconda3/lib/python3.11/site-packages/jupyterlab/staging/yarn.js:743:8770)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

[I 2024-09-14 15:51:53.635 ServerApp] Package notebook_shim took 0.0000s to import
[W 2024-09-14 15:51:53.635 ServerApp] A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2024-09-14 15:51:53.880 ServerApp] Package panel.io.jupyter_server_extension took 0.2448s to import
[I 2024-09-14 15:51:53.880 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-09-14 15:51:53.881 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-09-14 15:51:53.882 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-09-14 15:51:53.884 ServerApp] notebook | extension was successfully linked.
[I 2024-09-14 15:51:53.968 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-09-14 15:51:53.968 ServerApp] panel.io.jupyter_server_extension | extension was successfully linked.
[I 2024-09-14 15:51:53.973 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-09-14 15:51:53.973 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-09-14 15:51:53.974 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-09-14 15:51:53.974 LabApp] JupyterLab extension loaded from /home/jie/anaconda3/lib/python3.11/site-packages/jupyterlab
[I 2024-09-14 15:51:53.974 LabApp] JupyterLab application directory is /home/jie/anaconda3/share/jupyter/lab
[I 2024-09-14 15:51:53.974 LabApp] Extension Manager is 'pypi'.
[I 2024-09-14 15:51:53.975 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-09-14 15:51:53.976 ServerApp] notebook | extension was successfully loaded.
[I 2024-09-14 15:51:53.976 ServerApp] panel.io.jupyter_server_extension | extension was successfully loaded.
[I 2024-09-14 15:51:53.976 ServerApp] The port 8888 is already in use, trying another port.
Traceback (most recent call last):
  File "/home/jie/anaconda3/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jie/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/application.py", line 618, in launch_instance
    serverapp = cls.initialize_server(argv=args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jie/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/application.py", line 588, in initialize_server
    serverapp.initialize(
  File "/home/jie/anaconda3/lib/python3.11/site-packages/traitlets/config/application.py", line 113, in inner
    return method(app, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jie/anaconda3/lib/python3.11/site-packages/jupyter_server/serverapp.py", line 2609, in initialize
    self.init_httpserver()
  File "/home/jie/anaconda3/lib/python3.11/site-packages/jupyter_server/serverapp.py", line 2432, in init_httpserver
    self._find_http_port()
  File "/home/jie/anaconda3/lib/python3.11/site-packages/jupyter_server/serverapp.py", line 2479, in _find_http_port
    sockets = bind_sockets(port, self.ip)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jie/anaconda3/lib/python3.11/site-packages/tornado/netutil.py", line 162, in bind_sockets
    sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address

解决方案

通过指定 --ip后,发现程序已可成功运行。

jupyter notebook --ip=127.0.0.1

pycharm 设置

在这里插入图片描述
在pycharm jupyter 的设置中,设置:

notebook --no-browser --ip=127.0.0.1

在这里插入图片描述

然后, pycharm 就可以运行 jupyter .ipynb 文件。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jieshenai

为了遇见更好的文章

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值