conda常用操作和配置镜像源

pip

临时使用国内镜像源

下载某一个包的时候,加上如下后缀就行

pip install xxx 
#中科大源、清华源、豆瓣源
-i https://pypi.mirrors.ustc.edu.cn/simple/
-i https://pypi.tuna.tsinghua.edu.cn/simple
-i https//pypi.doubanio.com/simple/ 

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uD8SZCjw-1664240931261)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220926103728097.png)]

永久使用国内镜像源

1、豆瓣源
pip config set global.index-url https//pypi.doubanio.com/simple/ 
2、清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
3、中科大源
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
4、配置成功会出现:

在这里插入图片描述

#保存路径
C:\Users\Administrator\AppData\Roaming\pip\pip.ini

打开保存路径的文件:

在这里插入图片描述

5、删除镜像源

直接将pip.ini文件删除即可

conda

0.出现 channels问题时候

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

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.文件所在位置(进行增删)

也可以通过打开文件来增加删除镜像源

在这里插入图片描述
在这里插入图片描述

conda常用命令

1、创建虚拟环境

conda  create  --name  env_name python=3.7 

在这里插入图片描述

遇到报错:

UnavailableInvalidChannel: HTTP 404 NOT FOUND for channel simple

先删除镜像

conda config --remove-key channels

添加镜像

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 --show channels

2、激活虚拟环境

conda activate env_name

在这里插入图片描述

3、退出当前环境

conda deactivate

在这里插入图片描述

4、删除环境

conda remove  --name  env_name  --all

在这里插入图片描述

5、复制虚拟环境

conda  create  --name  new_env_name  --clone  old_env_name

在这里插入图片描述

6、查看当前所有环境

conda  info  -e

在这里插入图片描述

7、查看当前虚拟环境下的所有安装包

conda list  
conda list  -n  env_name

在这里插入图片描述
在这里插入图片描述

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  update  conda
conda  update  anaconda

11、卸载

rm  -rf  anaconda
### 配置 Windows 系统上的 Conda 国内镜像源 对于 Windows 用户而言,配置 conda 使用国内镜像源可以显著提高包管理效率并减少因网络问题带来的困扰。具体操作如下: #### 修改 `.condarc` 文件 `.condarc` 是 conda 的全局或用户级别的配置文件,在此文件中指定镜像源地址能够使所有通过该环境执行的操作都受益于更快的速度。 如果希望临时更改当前会话中的频道而不影响长期设置,则可以在命令行输入相应指令完成即时调整;而对于永久性的变更则需编辑上述提到的配置文件[^2]。 #### 添加清华大学 TUNA 或中科大 USTC 镜像作为默认 为了将清华大学 TUNA 或中国科学技术大学 USTC 设定为新的默认下载位置之一,可以通过运行以下 PowerShell 或 CMD 命令实现: ```powershell conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes ``` 或者选择USTC镜像源: ```powershell conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ conda config --set show_channel_urls on ``` 这些命令将会把所选的镜像站加入到用户的 `channels` 列表里,并开启显示渠道网址的功能以便更好地追踪安装来[^4]。 #### 设置默认搜索顺序 为了让新添加的镜像成为优先查找的对象,还需要确保其位于列表顶部。这一步骤可通过重新排列已有的 channel 来达成目的。例如,要让 TUNA 成为主要仓库,可依次执行下面两条语句: ```powershell conda config --prepend channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main conda config --remove-key channels_default ``` 以上步骤完成后,重启 Anaconda Prompt 或者任何正在使用的终端窗口以应用最新的改动[^3]。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江小皮不皮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值