conda环境变量+常用操作+配置镜像源

、1、conda环境变量配置
根据我的上篇文章,应该都已经安装了conda和pycharm,然后可能会出现conda的没有配置到系统的环境变量上,这里首先教大家如何配置系统的环境变量,在进行后续操作,如果环境变量已经配置完毕可以自动跳过。

 

这种就是没有配置好环境变量,导致在命令行窗口打不开,下边教大家配置。

1、找到conda3的安装路径

 

2、类似与上述图片这种,然后复制路径。每个人的都不一样

C:\ProgramData\Anaconda3
C:\ProgramData\Anaconda3\Scripts
C:\ProgramData\Anaconda3\Library\bin
C:\ProgramData\Anaconda3\Library\mingw-w64\bin
C:\ProgramData\Anaconda3\Library\usr\bin
3、

打开如图所示的界面,点击高级系统设置。

4、再点击环境变量,进行编辑

5、打开后点击新建依次将第2部中复制好的路径新建到环境变量中,并将这些环境变量依次上移防止因优先级问题环境变量无法生效

6、确认配置完成后退出,然后按键盘win+R输入cmd,点回车键。

 

出现上述这种就说明配置conda环境完成,第一部分over。

2、conda常用操作
1、查看conda版本

conda --version
2、创建虚拟环境

conda create -n yidaqi python==3.8.5
3、激活虚拟环境,也就是进入我们创建好的虚拟环境。

conda activate yidaqi
4、退出当前环境

conda deactivate
5、删除某一个自己创建过的环境

conda remove -n yidaqi --all
6、复制之前的虚拟环境的东西到另一个虚拟环境里面

conda create -n new_yidaqi --clone yidaqi
7、查看当前所有的环境

conda info -e
8、查看当前虚拟环境下所有的包

conda list
8、导出/创建虚拟环境

conda env export > environment.yml # 导出当前虚拟环境
pip freeze > requirements.txt #pip 导出
conda env create -f environment.yml # 创建保存的虚拟环境
9、批量导出虚拟环境中的所有组件

conda list -e > requirements.txt # 导出
conda install --yes --file requirements.txt # 安装
10、升级conda两种方式都可

conda updata conda
conda updata anaconda
11、删除conda这个软件

rm -rf anaconda
3、conda配置国内镜像源
这一步的目的就是为了下载库、包的时候不至于下载的太慢,节约我们的时间。

因为我们在执行conda install或者pip install安装包的时候,很大程序上是因为你用的默认源导致的,可以尝试用国内提供的开源镜像,速度可以快速提升。

下边两个大家可以直接操作

1、中科大的源还稳定,不容易报错,操作步骤如下

conda config --remove-key channels
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple


2、清华大学的conda的镜像源,操作如下。

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/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes
大家后续安装的时候,可能会报一些带HTTP的错误信息,有一部分可能是由于镜像源的问题,下边给大家介绍一下镜像相关的一些操作,

1、临时使用一个国内镜像源单独安装一个包的时候

pip install xxx -i channal
#中科大源、清华源、豆瓣源
-i https://pypi.mirrors.ustc.edu.cn/simple/
-i https://pypi.tuna.tsinghua.edu.cn/simple
-i https//pypi.doubanio.com/simple/
2、配置国内源,但是一般情况下就用上边那两步骤就够了

2.1豆瓣源

pip config set global.index-url https//pypi.doubanio.com/simple/
2.2清华源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
2.3中科大源

pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
2.4配置成功会出现

 

#保存路径
C:\Users\Administrator\AppData\Roaming\pip\pip.ini
打开保存的文件夹

 

2.5删除这个镜像源

直接删除这个文件就ok

出现chanels文件的时候,列如

Collecting package metadata (current_repodata.json): failed

UnavailableInvalidChannel: The channel is not accessible or is invalid.
channel name: simple
channel url: https://pypi.tuna.tsinghua.edu.cn/simple
error code: 404

You will need to adjust your conda configuration to proceed.
Use `conda config --show channels` to view your configuration's current state,
and use `conda config --show-sources` to view config file locations.
解决办法1

conda clean -i
解决办法2

conda config --remove-key channels
常用镜像源操作 都在base环境下操作

1、查看目前存在的源

conda config --show-sources


2、 删除一个镜像源

conda config --remove channels https://pypi.tuna.tsinghua.edu.cn/simple
3、增加一个镜像源

# 清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
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/pkgs/free/
4、通过搜索时显示通道地址

conda config --set show_channel_urls yes
5、也可以通过找到源的txt文件的位置进行镜像源的删除。

后续会不断完善三部分内容。还有很多其他的镜像源,大家可以自行寻找

参考文献:
conda常用操作和配置镜像源_conda 源-CSDN博客
————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/m0_74055982/article/details/140220250

posted on 2024-07-14 11:57  独上兰舟1  阅读(934)  评论(0编辑  收藏  举报