gpt4 book ai didi

python-3.x - Jupyter 笔记本 Python 内核 - FileNotFoundError : [Errno 2] No such file or directory python3

转载 作者:行者123 更新时间:2023-12-05 06:07:52 25 4
gpt4 key购买 nike

问题

在Jupyter notebook中,如何解决找不到Python解释器的问题。

环境

  • Ubuntu 18.04
  • 使用 Python 3.7 的 Anaconda 环境

问题

启动一个jupyter notebook,用Python 3内核创建一个notebook,报错。 nlp_in_tensorflow 是一个已删除的 conda 环境。

Traceback (most recent call last):
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/web.py", line 1704, in _execute
result = await result
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/gen.py", line 769, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/notebook/services/sessions/handlers.py", line 72, in post
type=mtype))
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/gen.py", line 762, in run
value = future.result()
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/gen.py", line 769, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/notebook/services/sessions/sessionmanager.py", line 88, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/gen.py", line 762, in run
value = future.result()
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/gen.py", line 769, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/notebook/services/sessions/sessionmanager.py", line 101, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/tornado/gen.py", line 762, in run
value = future.result()
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/notebook/services/kernels/kernelmanager.py", line 176, in start_kernel
kernel_id = await maybe_future(self.pinned_superclass.start_kernel(self, **kwargs))
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/jupyter_client/multikernelmanager.py", line 185, in start_kernel
km.start_kernel(**kwargs)
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/jupyter_client/manager.py", line 313, in start_kernel
self.kernel = self._launch_kernel(kernel_cmd, **kw)
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/jupyter_client/manager.py", line 220, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/home/user/conda/envs/cs231n/lib/python3.7/site-packages/jupyter_client/launcher.py", line 131, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/home/user/conda/envs/cs231n/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/home/user/conda/envs/cs231n/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/conda/envs/nlp_in_tensorflow/bin/python3': '/home/user/conda/envs/nlp_in_tensorflow/bin/python3'

最佳答案

原因

Python 3 内核的 kernel.json 文件指向已删除的环境。

$ jupyter kernelspec list
Available kernels:
python3 /home/oonisim/.local/share/jupyter/kernels/python3

$ cat ~/.local/share/jupyter/kernels/python3/kernel.json
{
"argv": [
"/home/user/conda/envs/nlp_in_tensorflow/bin/python3", <----- Referring to the deleted environment
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}

资源

Multiple python environments, whether based on Anaconda or PythonVirtual environments, are often the source of reported issues. In manycases, these issues stem from the Notebook server running in oneenvironment, while the kernel and/or its resources, derive fromanother environment.

Another thing to check is the kernel.json file that will be located inthe aforementioned kernel specs directory identified by runningjupyter kernelspec list. This file will contain an argv stanza thatincludes the actual command to run when launching the kernel.Oftentimes, when reinstalling python environments, a previouskernel.json will reference an python executable from an old ornon-existent location. As a result, it’s always a good idea whenencountering kernel startup issues to validate the argv stanza toensure all file references exist and are appropriate.

修复

删除了 ~/.local/share/jupyter/kernels/python3/kernel.json。

相关问题

Jupyter is set-up to be able to use a wide range of "kernels", orexecution engines for the code. These can be Python 2, Python 3, R,Julia, Ruby... there are dozens of possible kernels to use. But inorder for this to happen, Jupyter needs to know where to look for theassociated executable: that is, it needs to know which path the pythonsits in.

These paths are specified in jupyter's kernelspec, and it's possiblefor the user to adjust them to their desires. For example, here's thelist of kernels that I have on my system:

关于python-3.x - Jupyter 笔记本 Python 内核 - FileNotFoundError : [Errno 2] No such file or directory python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65300509/

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