命令(!xxx), 出错: OSError: “/bin/bach“ shell not found"/>
解决 Jupyter notebook 运行SHELL 命令(!xxx), 出错: OSError: “/bin/bach“ shell not found
我在JUPYTER NOTEBOOK新增加一个环境ai, 进入后,在NOTEBOOK的代码行中运行 SHELL 命令 (!pip install gradio) 出错:
import os
os.environ
!pip install gradio ---------------------------------------------------------------------------
OSError Traceback (most recent call last)
......
......
......File ~/anaconda3/envs/ai/lib/python3.8/site-packages/IPython/utils/_process_posix.py:57, in ProcessHandler.sh(self)55 self._sh = pexpect.which(shell_name)56 if self._sh is None:
---> 57 raise OSError('"{}" shell not found'.format(shell_name))59 return self._shOSError: "/bin/bach" shell not found`
翻遍STACKOVERFLOW, CSDN 没有找到答案, 最后在JUPYTER 的github 官网找到提示, 原因是ipykernel 没有定义 shell, 解释器运行时不认得 !, 需要改kernel.json 配置文件.
真是用了这么久的notebook, 第一次碰到, 可能是新版jupyter的一个安装BUG.
如下修改:
打开对应环境下的kernel.json, 文件所在位置:
/home/royliu/anaconda3/envs/ai(此处换成你的环境名称)/share/jupyter/kernels/python3/kernel.json
增加代码:
“env”: {
“SHELL”: “sh”
},
增加后如下:
{"argv": ["/home/royliu/anaconda3/envs/ai/bin/python","-m","ipykernel_launcher","-f","{connection_file}"],"display_name": "Python 3 (ipykernel)","language": "python","env": {"SHELL": "sh"},"metadata": {"debugger": true}
}
保存, 重启 JUPYTER NOTEBOOK, 再执行文件中的! 命令即可成功.
原创文章, 未经许可, 不得转载!
更多推荐
解决 Jupyter notebook 运行SHELL 命令(!xxx), 出错: OSError: “/bin/bach“ shell not found
发布评论