gpt4 book ai didi

python - jupyter notebook FileNotFoundError - 查找错误的 anaconda 目录

转载 作者:行者123 更新时间:2023-12-04 02:06:34 28 4
gpt4 key购买 nike

我在打开 jupyter notebook 文件时遇到问题。 Jupyter notebook 在寻找 Python 时给我一个 FileNotFoundError 错误:

Traceback (most recent call last):
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/base/handlers.py", line 503, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 75, in post
type=mtype))
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 285, in wrapper
yielded = next(result)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 87, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/manager.py", line 257, in start_kernel
**kw)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/manager.py", line 203, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/subprocess.py", line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/myusername/anaconda3/envs/py3/bin/python'

我正在上在线类(class)。我首先创建了一个 conda 环境,如下所示:

conda create --name dlnd python=3
source activate dlnd
conda install numpy matplotlib pandas jupyter notebook

然后我尝试打开类中给出的文件:

jupyter notebook dlnd-your-first-neural-network.ipynb

这是错误发生的时候。

我怀疑问题是我没有 /Users/myusername/anaconda3/ 目录(因此没有 FileNotFoundError)。我所有的 anaconda 东西都安装在 /Users/myusername/anaconda/ 中,我已经使用 jupyter notebooks 几个星期了,在各种环境中运行各种 .ipynb 文件,没有重大问题。

我不确定为什么 jupyter notebook 在特定实例中查找 anaconda3/。我尝试重新安装,但所有内容都再次安装在 /Users/myusername/anaconda/ 中。

有更多经验的人知道我错过了什么吗?

在 10.11 上使用 Macbook pro

最佳答案

基于@NehalJWani suggested post ,我找到了 /Users/myusername/Library/Jupyter/kernels/python3/kernal.json,如下所示:

{
"argv": [
"/Users/myusername/anaconda3/envs/py3/bin/python",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}

并修改它以指定 anaconda 而不是 anaconda3:

{
"argv": [
"/Users/myusername/anaconda/envs/py3/bin/python",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}

尝试重新运行jupyter notebook,新的错误是:

FileNotFoundError: [Errno 2] No such file or directory: 
'/Users/myusername/anaconda/envs/py3/bin/python'

这是朝着正确方向迈出的一步,因为至少现在我们正在寻找 anaconda 而不是 anaconda3。然而,它也在寻找 envs/py3/,而我没有 py3 环境。

查看@darthbith 建议的.ipynb 文件,文件元数据是:

"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

我看到这里指定了python3内核,但没有指定py3环境。

最终我只是制作了一个 py3 环境来代替我想要的 dlnd 环境:

conda create -n py3 python=3

尝试再次运行笔记本时出现此错误:

/Users/myusername/anaconda/envs/py3/bin/python:
No module named ipykernel

所以我只安装了 ipykernal 以及我最终可能需要的其他依赖项:

conda install ipykernel numpy matplotlib pandas jupyter notebook

现在可以了。

关于python - jupyter notebook FileNotFoundError - 查找错误的 anaconda 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42896215/

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