欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Conda 环境和更改镜像源

最编程 2024-03-12 10:52:50
...

前言

记录常用的conda命令,快速修改conda环境

1,创建和修改镜像源

  • 查看conda的环境目录

    conda info --envs

  • 激活一个conda环境

    conda activate envs

  • 创建conda环境

    conda create -n envs_name python=3.7

  • 删除环境

    conda remove -n envs_name --all

2,使用镜像源

  • 有时候我们会遇到第三方源找不到库的情况

    ERROR: Could not find a version that satisfies the requirement xxx

  • 这个可能是该源没有更新,导致安装失败,这个时候如果换了很多第三方源都安装不了时,我们就需要使用官方源进行安装

    pip install numpy -i http://mirrors.aliyun.com/pypi/simple/ # 阿里云
    pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple # 清华源
    pip install numpy -i https://pypi.org/simple # 官方源

3,修改pip源

  • 方法一
    通过新建pip文件夹实现,首先在文件资源管理器中搜索 %APPDATA% ,新建一个pip文件夹,新建pip.txt文件,输入以下内容,然后保存,更改后缀为ini,完成。

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

  • 方法二
    或者直接输入以下命令也可以实现永久换源

    pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

3,修改 conda 源

  • 方法一
    在以下文件夹下找到 .condarc 文件,然后用文本打开,按照例子修改 channels 内容,然后保存即可。

    channels:
    - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    - defaults

  • 方法二
    在命令提示符中输入以下内容即可:

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.aliyun.com/pypi/simple/
    conda config --set show_channel_urls yes

4,查看和还原

若想查看自己的 channel 有哪些,执行:

conda config --show channels

若想还原默认源,执行:

conda config --remove-key channels

5,常用的镜像源:

(1)豆瓣:http://pypi.douban.com/simple/
(2)阿里云 http://mirrors.aliyun.com/pypi/simple/
(3)清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
(4)中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple

推荐阅读