anaconda配置新的虚拟环境(自用)

六月份的时候配置tensorflow把坑都踩过一遍了,没想到三个月后配置pytorch我又忘了……为防悲剧再现,决定开篇博文记录一下。

一、创建新的虚拟环境

conda create -n your_env_name python=3.8

此处your_env_name为新的虚拟环境的命名,3.8为python的版本。

二、激活虚拟环境

conda activate your_env_name

三、将虚拟环境作为新内核添加到Juypyter

1.安装ipykernel

conda install ipykernel

值得注意的是因为我两次学习配置时都在科学上网,所以如果出现了这样的报错

An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get you on your way. 'https//mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64'

请务必先去关闭vpn,不要再搜百度看教程再来配置一边镜像源了,清华源它很好不用挂念……

既然提到了那就在这里贴一下关于镜像源的几个操作和命令,方便日后

·查看下载镜像

conda config --show channels

·添加下载镜像源

conda config --add channels https://mirrors.aliyun.com/pypi/simple/

conda config --add channels https://pypi.mirrors.ustc.edu.cn/simple/

conda config --add channels http://pypi.douban.com/simple/

conda config --add channels https://pypi.tuna.tsinghua.edu.cn/simple/

分别是阿里云、中国科技大学、豆瓣、清华源

2023.2.3 更新,重配服务器的镜像源后发现清华源出了点问题,搜了一下更新镜像源设置

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
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/msys2/

·删除下载镜像源

conda config --remove channels https://mirrors.aliyun.com/pypi/simple/

此处以阿里云为例

·清空源命令/重置源配置

conda config --remove-key channels

2.生成ipykernel的配置文件

python -m ipykernel install —-name your_env_name

这里要注意的是--name后接你的虚拟环境名,不能不一致

3.查看已有的kernel

jupyter kernelspec list

此时再输入jupyter notebook就可以进入jupyter notebook了,不出意外的话新的虚拟环境内核已经可以使用啦~

4.删除jupyter 内核

jupyter kernelspec remove kernelname

5.一步到位添加所有内核

退出到(base)环境

conda install nb_conda

五、进入虚拟环境后查看该环境下的库

conda list

六、退出虚拟环境

conda deactivate

七、查看现有的虚拟环境

conda env list

八、删除环境以及下属安装包

conda remove -n your_env_name --all

九、导出虚拟环境配置

进入你想要导出的虚拟环境后输入

conda env export > environment.yaml

十、通过导出的.yaml文件新建虚拟环境并配置相应库

conda env create -f environment.yaml

猜你喜欢

转载自blog.csdn.net/m0_58547949/article/details/126973011