问题描述
在 zsh 中进入 tmux,新建了 my_jupyterlab 会话,在该会话中运行 jupyter lab 提示“zsh: command not found: jupyter” 的错误!
问题分析
没有将 jupyter 添加到用户目录下的 .zshrc 隐藏配置文件中
解决方法:
- 回到 bash 下运行命令:pip show jupyter,查看通过 pip install 命令安装的 jupyter 的路径,得到结果如下:
Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD
Location: /home/用户名/anaconda3/lib/python3.7/site-packages
Requires: ipywidgets, ipykernel, nbconvert, qtconsole, jupyter-console, notebook
Required-by:
- (说明:如果记得自己的 jupyter 路劲,以上步骤可以省略)
- 根据以上路径提示(注意这里会因安装 Anaconda 的路径不同而不同),找到 jupyter 的所在的 bin 目录的路径,即:/home/用户名/anaconda3/bin,拷贝该路径以备后面使用
- 通过 vim ~/.zshrc 打开用户目录下的 .zshrc 配置文件
- 将上面复制的路径以如下方式追加到 .zshrc 文件的文档尾,保存
export PATH=/home/用户名/anaconda3/bin/:$PATH
- 运行 source ~/.zshrc,使其生效
- 关闭原来建立的 tmux(注意一定要关闭原来的 tmux 会话,不然还是会提示该错误,这是因为原来的 tmux 会话还是加载的没有添加 jupyter 命令的 zsh 配置文件,虽然已经通过 source 使其生效)
tmux kill-session -t my_jupyterlab
- 新建一个 tmux 会话
tmux new -s my_jupyterlab
- 进入 zsh,再在 tmux 会话中启动 jupyter lab
jupyter lab --port 端口号