anaconda配置清华源以及常用操作

Anaconda安装

bash Anaconda2-4.4.0-Linux-x86_64.sh

简单版

vi ~/.condarc

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

复杂版 

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 --set show_channel_urls yes
  • 添加Pytorch镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

# for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
  • 恢复默认镜像
conda config --remove-key channels # 恢复默认下载源
  • 更改pip源
# Linux环境
cd ~/
mkdir .pip
cd .pip
sudo vim pip.conf

# 加入如下内容(其实就是指定tuna源)
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple 
[install]  
trusted-host=pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true  
timeout = 6000
  • Pytorch安装
conda install pytorch
conda install pytorch=0.4.1 cuda92 -c pytorch(实测,然后其他pytorch相关包用conda安装,不相关用pip)
conda install pytorch torchvision cudatoolkit=8.0 -c pytorch

参考:180801 Anaconda安装及添加清华Pytorch镜像_keras-applications 1.0.4 requires keras>=2.1.6, bu-优快云博客

conda常用操作

  • 查看配置情况
conda info
  • 更新
conda update conda
conda update --all
  • 删除缓存
conda clean -p      //删除没有用的包
conda clean -t      //tar打包
conda clean -y --all //删除所有的安装包及cache
  • 查看当前存在哪些虚拟环境
conda env list 或 conda info -e
  • 创建python虚拟环境
conda create -n env_name python=x.x(3.5)
  • 激活(或切换不同python版本)的虚拟环境
conda activate env_name
  • 对虚拟环境安装额外的包
conda install -n env_name package_name(pandas)
  • 关闭虚拟环境
conda deactivate
  • 删除环境中的某个包
conda remove --name env_name package_name
  • 删除虚拟环境
conda remove -n env_name --all
  • 激活terminal
  • conda init powershell
    
    # terminal(管理员)
    
    Set-ExecutionPolicy RemoteSigned

<think>好的,用户想配置Anaconda使用清华镜像源,我需要一步步指导他们怎么做。首先,我应该回忆一下清华镜像源的配置方法。记得可以通过修改.condarc文件,或者使用conda config命令来添加通道。 用户可能使用的是Windows系统,因为提到无法直接创建.condarc文件。所以可能需要先生成这个文件,再修改内容。我应该先建议他们运行conda config --set show_channel_urls yes来生成文件,这样用户就不用自己手动创建了。 接下来,要编辑.condarc文件,替换为清华的镜像源地址。需要确保语法正确,缩进和格式不能出错。可能需要提供具体的YAML内容,包括defaults、custom_channels和channel_priority的设置。 另外,用户可能需要清除索引缓存,使用conda clean -i,这样可以确保后续安装使用新的镜像源。可能还需要验证配置是否成功,比如执行conda create命令测试下载速度。 还要注意不同操作系统的路径问题,比如Windows用户.condarc的位置在C:\Users\用户名下,而Linux和macOS在用户主目录。需要分系统说明,避免用户找不到文件。 另外,用户可能遇到的问题包括文件权限、路径错误或者镜像源地址变更。需要提醒他们如果配置后无法使用,可能需要检查网络或镜像状态。可能还需要提到恢复默认配置的方法,比如删除.condarc文件或者使用conda config命令移除添加的通道。 最后,生成相关问题时要考虑用户可能的后续疑问,比如如何恢复默认源、其他镜像源推荐、更新包时的问题等。这样能帮助用户全面了解相关配置和故障排除。</think>### Anaconda配置清华镜像源教程 通过修改`.condarc`文件可实现镜像源配置,具体步骤如下: **1. 生成配置文件(仅Windows需要)** ```bash conda config --set show_channel_urls yes ``` 该命令会在用户目录自动创建`.condarc`文件[^1] **2. 编辑配置文件** 用文本编辑器打开`.condarc`,替换为以下内容: ```yaml channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/ channel_priority: flexible ``` **3. 清除缓存** ```bash conda clean -i ``` **4. 验证配置** ```bash conda create -n test_env numpy ``` 观察下载速度是否提升 **文件路径说明** - Windows:`C:\Users\<用户名>\.condarc` - Linux/macOS:`~/.condarc`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值