项目场景:
有时候安装一些依赖包,网速慢,直接超时,可以指定国内源镜像。
pip install -i 国内镜像地址 包名
或者 python -m pip install -i 国内镜像地址 包名
也可以在 pip的时候控制超时, 具体参数为“–default-timeout=100”,
例如:
pip install -i https://mirrors.aliyun.com/pypi/simple/ numpy
python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ numpy
python -m pip --default-timeout=100 install -i https://mirrors.aliyun.com/pypi/simple/ numpy
国内常用源镜像地址:
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:https://pypi.douban.com/simple/
note:新版ubuntu要求使用https源,要注意
生成: pip freeze > requirements.txt
导入: pip install -r requirements.txt
出现Looking in indexes: http://pypi.douban.com/simple/:
Remainder of file ignored
Looking in indexes: http://pypi.douban.com/simple/
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
ERROR: Could not find a version that satisfies the requirement setuptools (from versions: none)
ERROR: No matching distribution found for setuptools
添加trusted-host 选项,否则使用的时候会提示不受信任
例如:
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com '模块版本'
1、修改源方法(永久修改)
linux:
修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
查看 镜像地址:
pip3 config list
windows:
直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,
windows在%HOMEPATH%\pip\pip.ini
内容如下:
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
配置国内镜像源方法
1、显示镜像源
conda config --show channels
如图,我的是默认设置
2、添加新镜像源
conda config --add channels [urls…]
如图所示,添加成功
3、删除镜像源
conda config --remove-key channels 删除所有的镜像源,恢复到默认
conda config --remove channels [urls] 删除指定的镜像源
如图所示,删除成功
4、设置搜索时显示通道地址
conda config --set show_channels_urls yes
5、conda 安装指定的源
conda install -c [urls] [lib_name] # 这两个参数自定义