1、Anaconda (miniconda) 创建虚拟环境
anaconda命令创建python版本为x.x,名字为your_env_name的虚拟环境
conda create -n your_env_name python=x.x
2、镜像源配置
切换清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes
查看已安装源
conda config --show-sources
删除安装源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
换回安装源
conda config --remove-key channels
3、激活要使用的环境
激活环境
conda activate your_env_name
切换环境
conda deactivate # 一定要先deactivate,不然python环境会出问题
conda activate your_other_env_name
删除虚拟环境
conda env remove --name your_env_name
4、将虚拟环境添加到jupyter lab kernel内核
激活环境后,安装ipykernel
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ipykernel
创建内核
将虚拟环境 your_env_name 导入jupyter的kernel中(自己设置显示的名字为 your_kernel_name)
python -m ipykernel install --name your_env_name --display-name your_kernel_name
更新jupyter,新建的your_env_name的kernel内核已经显示,名字为 your_kernel_name
删除kernel
jupyter kernelspec uninstall myenv
本文详细介绍了如何使用conda创建虚拟环境,切换镜像源,激活和管理环境,以及将虚拟环境添加到Jupyter Lab的kernel中,便于进行Python版本隔离和项目管理。

4053

被折叠的 条评论
为什么被折叠?



