Anaconda中安装第三方库指定镜像源

1. pip安装方法

1.1 临时使用:
pip install PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install PyQt5-tools -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
1.2 长期使用:

在“C:\Users\你的用户名\”目录下创建“pip”目录,“pip”目录下创建“pip.ini”文件(注意:以UTF-8 无BOM格式编码)。

“pip.ini”文件内容:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

在window下面用记事本、notepad等编辑文件的时候,如果保存为UNICODE或UTF-8,分别会在文件的开头加上两个字节“\xFF\xFE”和三个字节“\xEF\xBB\xBF”。 即:BOM。此时pip在读取配置文件时会报"ConfigParser.MissingSectionHeaderError: File contains no section headers."错误,此时采用以下Python脚本对pip.ini进行处理即可:

import re
def remove_BOM(config_path):
  content = open(config_path).read()
  content = re.sub(r"\xfe\xff","", content)
  content = re.sub(r"\xff\xfe","", content)
  content = re.sub(r"\xef\xbb\xbf","", content)
  open(config_path, 'w').write(content)

if __name__ == '__main__':
    config_path = "C:\Users\Administrator\pip\pip.ini"  # 此处路径修改为你的配置文件所对应地路径
    remove_BOM(config_path)

2. conda安装方法

2.2 长期使用:

修改配置文件.condarc

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
show_channel_urls: true
ssl_verify: true

或者

输入命令:

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 config --remove-key channels (移除镜像源)
conda config --remove channels  指定的URL  # 删除原来镜像

查看镜像源:conda config --show channels
输入:conda info 验证是否配置成功。

常用镜像源:

阿里:http://mirrors.aliyun.com/pypi/simple/

清华:https://pypi.tuna.tsinghua.edu.cn/simple/

豆瓣:http://pypi.douban.com/

  • 7
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值