一、anaconda配置镜像
查看源:conda config --show-sources
在Mac and Linux下:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
在Windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
换回默认源:conda config --remove-key channels
详细:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
或者:
执行conda命令:conda config
会创建conda的配置文件,使用search everything 查找 .condarc 并打开,在里面添加
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
To get all keys and their values:
conda config --get
To get the value of a specific key, such as channels:
conda config --get channels
To add a new value, such as http://conda.anaconda.org/mutirri, to a specific key, such as channels:
conda config --add channels http://conda.anaconda.org/mutirri
To remove an existing value, such as http://conda.anaconda.org/mutirri from a specific key, such as channels:
conda config --remove channels http://conda.anaconda.org/mutirri
To remove a key, such as channels, and all of its values:
conda config --remove-key channels
To configure channels and their priority for a single environment, make a .condarc
file in the root directory of that environment.
二、pip配置镜像
1.Linux下:
修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url至tuna,内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
2.在Windows下:
直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3.临时使用:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
4.pip国内源:
新版ubuntu要求使用https源,要注意。
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
三、conda与pip区别:
conda包始终是编译的二进制分发版,而不是源代码分发版.
国内用pip网速比conda快。
(1)pip安装的是python wheel或者源代码的包,需要有编译器的支持,pip不支持python语言之外的依赖项。
pip从pypi下载所需的python包,但是pip不会自动处理包之间的依赖关系;可以修改安装源为https://pypi.tuna.tsinghua.edu.cn/simple/ 。
pip如果无法编译源代码,那么安装它可能会很痛苦(这在Windows上尤其如此,但如果软件包有一些困难的C或FORTRAN库,甚至在Linux上也是如此)
(2)conda支持非python语言写的依赖项,比如mkl cuda这种c c++写的包。conda安装的都是编译好的二进制包,不需要编译。pip没有某个编译器可能会失败,conda不会。conda装东西的体积一般比较大,尤其是mkl这种动不动几百兆甚至一G多。
pip几乎就是个安装包的软件,conda是个环境管理的工具。conda自己可以用来创建环境,pip不能,需要依赖virtualenv之类的。意味着你能用conda安装python解释器,pip不行。这一点我觉得是conda很有优势的地方,用conda env可以很轻松地管理很多个版本的python,pip不行。
conda会检查当前环境下所有包之间的依赖关系,conda基本上安上了就能保证工作,pip有时候可能装上了也不work。这个区别也导致了安装的时候conda算依赖项的时间比pip多很多,而且重新安装的包也会更多(会选择更新旧包的版本)。
conda结合了pip和virtualenv两者的功能。
conda在python-site-packages之外管理python库依赖关系。
pip只关注Python,而忽略了非Python的包依赖,such as HDF5, MKL, LLVM, etc,它们的源码中没有setup.py,并且不向Python的site-packages里安装。
(3)virtualenv是一个环境管理工具,使用virtualenv可以创建一个完全隔离的环境,但virtualenv只能创建基于本机已存在的python版本的虚拟环境;使用virtualenv创建完成环境以后,可以使用pip安装python包,也可以使用conda安装python包。