gpt4 book ai didi

macos - 在 localhost 上启动 Jupyter Notebook 会导致 '[Errno 49] Can' t 分配请求的地址,但是 ip=127.0.0.1 有效

转载 作者:行者123 更新时间:2023-12-05 00:46:29 24 4
gpt4 key购买 nike

尝试启动 Jupyter Notebook 时出现以下错误

$ Jupyter Notebook
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jupyter_core/application.py", line 268, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/traitlets/config/application.py", line 663, in launch_instance
app.initialize(argv)
File "</Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/decorator.py:decorator-gen-7>", line 2, in initialize
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/notebook/notebookapp.py", line 1720, in initialize
self.init_webapp()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/notebook/notebookapp.py", line 1482, in init_webapp
self.http_server.listen(port, self.ip)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 151, in listen
sockets = bind_sockets(port, address=address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/netutil.py", line 174, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 49] Can't assign requested address

但是,当我指定 127.0.0.1 的 ip 地址(即不是 'localhost')时,Jupyter Notebook --ip=127.0.0.1 它工作得非常好。

另外,当我 ping localhost 时,它返回的本地主机实际上是 127.0.0.1。

$ ping localhost
PING localhost.localdomain (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.034 ms

我检查了 etc/hosts 和 private/etc/hosts,但都没有指定 localhost(或任何与此相关的内容)。

我正在尝试解决此问题,因为我在 PyCharm 中运行 Jupyter Notebooks,您无法创建一个简单的快捷方式来仅在 127.0.0.1 副 'localhost' 上运行。 (我知道没有简单的快捷方式,如果我错了,请纠正我)我可以在 Pycharm 中的 127.0.0.1 上启动,但它需要多个步骤并且很麻烦。我只是希望它通过其预期的“localhost”配置作为默认配置工作。

最佳答案

答案记入@jackw11111

为你的 jupyter notebook 生成一个配置文件

$ jupyter notebook --generate-config

使用您喜欢的编辑器进入这个新的配置文件

$ nano ~/.jupyter/jupyter_notebook_config.py

将以下行添加到文件中,使其成为默认监听服务器

c.NotebookApp.ip = '127.0.0.1'

关于macos - 在 localhost 上启动 Jupyter Notebook 会导致 '[Errno 49] Can' t 分配请求的地址,但是 ip=127.0.0.1 有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60271829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com