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/

在Python中安装第三方库有几种常用的方法。首先,可以使用pip命令行直接安装。这是最常见和推荐的方法。具体步骤是打开终端或命令提示符,然后运行"pip install 包名"的命令,其中"包名"是你想要安装第三方库的名称。 除了使用pip命令行安装,还可以通过指定国内的安装来加快安装速度。可以使用"pip install -i 国内地址 包名"的命令来安装,其中"国内地址"是你选择的国内镜像源的网址。 还有一种安装第三方库的方法是直接使用.whl文件进行安装。你可以从第三方库的官方网站或其他可信的来下载.whl文件,然后使用"pip install 文件名.whl"的命令来安装库。 最后,一些Python的发行版(如Anaconda)也提供了自己的包管理系统,可以通过该系统安装第三方库。具体使用方法可以参考该发行版的文档或官方网站。 如果你需要下载第三方库,你可以访问python库下载地址https://www.lfd.uci.edu/~gohlke/pythonlibs/,这个网址提供了很多常用的第三方库的下载链接。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [最全总结Python 第三方库安装方法](https://blog.csdn.net/xj4math/article/details/116750892)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python如何安装第三方库](https://blog.csdn.net/qq_52928524/article/details/119972212)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值