升级JupyterLab 4后仍启动旧版本3,如何控制启动版本?
手动控制JupyterLab版本的解决方案
升级JupyterLab 4后,jupyter lab默认启动旧版3的情况下,无需卸载旧版,可通过以下方式手动指定启动版本:
方法1:直接调用对应版本的可执行文件
先定位不同版本的jupyter-lab安装路径:
- Linux/macOS:执行
which -a jupyter-lab,会列出所有已安装的版本路径 - Windows:执行
where jupyter-lab,获取对应路径
之后直接使用绝对路径启动目标版本:
# 启动JupyterLab 4 /path/to/jupyterlab4/bin/jupyter lab # 启动JupyterLab 3 /path/to/jupyterlab3/bin/jupyter lab
方法2:用虚拟环境隔离版本
通过conda或venv创建独立环境,分别安装不同版本的JupyterLab,激活对应环境后即可启动目标版本:
使用conda的示例:
# 创建并激活JupyterLab 3环境 conda create -n jupyterlab3 jupyterlab=3 -y conda activate jupyterlab3 jupyter lab # 启动3版本 # 创建并激活JupyterLab 4环境 conda create -n jupyterlab4 jupyterlab=4 -y conda activate jupyterlab4 jupyter lab # 启动4版本
使用venv的示例(Python内置):
# 创建并激活JupyterLab 3环境 python -m venv jupyterlab3-env source jupyterlab3-env/bin/activate # Linux/macOS # jupyterlab3-env\Scripts\activate # Windows pip install jupyterlab==3.* jupyter lab # 创建并激活JupyterLab 4环境 python -m venv jupyterlab4-env source jupyterlab4-env/bin/activate # Linux/macOS # jupyterlab4-env\Scripts\activate # Windows pip install jupyterlab==4.* jupyter lab
方法3:临时修改PATH环境变量
通过调整PATH优先级,让系统优先调用目标版本的jupyter-lab:
# Linux/macOS下临时切换到JupyterLab 4 export PATH=/path/to/jupyterlab4/bin:$PATH jupyter lab # 临时切换到JupyterLab 3 export PATH=/path/to/jupyterlab3/bin:$PATH jupyter lab
如果需要永久默认启动某版本,可将对应路径添加到shell配置文件(如~/.bashrc、~/.zshrc)的PATH开头。
内容的提问来源于stack exchange,提问作者markling
相关产品推荐
相关产品推荐

