解决 Jupyter notebook 运行SHELL 命令(!xxx), 出错: OSError: “/bin/bach“ shell not found

编程入门 行业动态 更新时间:2024-10-25 06:31:53

解决 Jupyter notebook 运行SHELL <a href=https://www.elefans.com/category/jswz/34/1771323.html style=命令(!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

本文发布于:2023-06-25 17:23:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/881931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   SHELL   Jupyter   notebook   xxx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!