> 文章列表 > 环境搭建04-Ubuntu16.04更改conda,pip的镜像源

环境搭建04-Ubuntu16.04更改conda,pip的镜像源

环境搭建04-Ubuntu16.04更改conda,pip的镜像源

我常用的pipy国内镜像源:

https://pypi.tuna.tsinghua.edu.cn/simple    # 清华
http://mirrors.aliyun.com/pypi/simple/      # 阿里云
https://pypi.mirrors.ustc.edu.cn/simple/    #中国科技大学

1、将conda的镜像源修改为国内的镜像源

先查看conda安装的信息:

conda info   ## channel URLs中为conda镜像源

这里,我已经将conda的镜像源修改为清华的镜像源
修改镜像源有两种方法:命令行和修改文件

使用命令行添加镜像源:
## 添加镜像源命令:conda config --add channels “channel url” 
## 删除镜像源命令:conda config --remove channels “channel url”
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
conda info  ## 查看修改后的镜像源
修改.condarc文件,在文件中添加清华镜像源
gedit ~/.condarc

注意:修改之后如果安装工具包还是很慢,可以将https修改为http,就可以快速的下载工具包了。我遇到了这样的情况。

2、将pip的镜像源修改为国内的镜像源

第一种方法:

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

第二种方法:
在根目录下查看是否有清.pip文件:

ls -a

如果没有,创建该文件

mkdir ~/.pip

打开pip.conf,在文件中添加镜像

gedit ~/.pip/pip.conf

在pip.conf中添加:

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

3、批量导入/导出pip环境

(1)批量导出pip环境:
freeze 查询各种安装包的版本, > 重定向到requirements文本,文本名字可随意命名

pip freeze > requirements.txt 

此时安装包扩展被备份到requirements.txt
(2)批量安装pip环境:
首先,创建对应python版本的conda env环境;
然后,安装导出的各种安装包, -r 表示逐行读取安装

pip install -r requirements.txt