Python pip更换镜像源问题及解决
Python pip更换镜像源问题
常用的镜像源:
- 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
- 阿里云:https://mirrors.aliyun.com/pypi/simple/
- 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
1. 临时使用镜像源
如果只是偶尔需要使用镜像源,可以在安装包时通过 -i 参数指定。
例如:
pip install <package_name> -i https://pypi.tuna.tsinghua.edu.cn/simple
这里的 -i 参数后面跟着的是镜像源的URL。
例如:
安装numpy:
# 清华镜像 pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple # 阿里云镜像 pip install numpy -i https://mirrors.aliyun.com/pypi/simple/
2. 永久配置镜像源
为了避免每次安装包时都手动指定镜像源,可以通过配置文件永久设置镜像源。
例如:
# 永久配置阿里云镜像源 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
验证配置是否生效:
运行以下命令查看当前配置:
pip config list
3. 附:针对 Conda 的镜像配置
如果你使用 conda,可编辑 ~/.condarc(Linux/macOS)或 C:\Users\<用户名>\.condarc(Windows),添加以下内容(以清华镜像为例):
channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
总结
- 临时使用:直接在命令中添加
-i <镜像源地址>。 - 永久生效:修改
pip或conda的配置文件。 - 推荐使用清华大学或阿里云等国内镜像源,速度更快。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Pandas中`ValueError: cannot reindex from
在Pandas中,ValueError: cannot reindex from a duplicate axis错误通常发生在尝试对包含重复索引的DataFrame或Series进行重新索引(reindex)时,所以本文介绍了Pandas中`ValueError: cannot reindex from a duplicate axis`错误分析及解决办法,需要的朋友可以参考下2024-07-07
详解centos7+django+python3+mysql+阿里云部署项目全流程
这篇文章主要介绍了详解centos7+django+python3+mysql+阿里云部署项目全流程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-11-11
在tensorflow中设置使用某一块GPU、多GPU、CPU的操作
今天小编就为大家分享一篇在tensorflow中设置使用某一块GPU、多GPU、CPU的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-02-02
Win10 GPU运算环境搭建(CUDA10.0+Cudnn 7.6.5+pytroch1.2+tensorflow1.
熟悉深度学习的人都知道,深度学习是需要训练的,本文主要介绍了Win10 GPU运算环境搭建,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2021-09-09


最新评论