当前位置: 首页 > news >正文

pypi 配置国内镜像

pypi 国内镜像目前有:

  • 阿里云(aliyun) - https://mirrors.aliyun.com/pypi/simple/
  • 豆瓣(douban) - https://pypi.douban.com/simple/
  • 清华大学(tuna) - https://pypi.tuna.tsinghua.edu.cnopen in new window
  • 中国科学技术大学 - http://pypi.mirrors.ustc.edu.cn/
临时配置

手动指定源,可以在pip后面跟-i 来指定源,比如用豆瓣的源来安装web.py框架:

pip install -i http://pypi.douban.com/simple/ gevent

pip3 install pip --upgrade -i https://mirrors.aliyun.com/pypi/simple/

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

easy_install -i http://pypi.douban.com/simple/ gevent
永久配置

配置文件指定源,linux下修改~/.pip/pip.conf,如果没这文件则创建。

mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF 
[global]
trusted-host=mirrors.aliyun.com
index-url=https://mirrors.aliyun.com/pypi/simple/
EOF

easy_install配置国内源

cat > ~/.pydistutils.cfg << EOF 
[easy_install]
index-url=https://mirrors.aliyun.com/pypi/simple/ 
find-links=https://mirrors.aliyun.com/pypi/simple/
EOF

windows配置

文件夹窗口输入 :

%APPDATA%

新建一个pip文件夹,在pip文件夹里面新建一个配置文件pip.ini

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

清华源

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
命令行配置

可以直接通过命令行修改 pip 的配置:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
常见问题与解决方法
配置后安装依赖仍然很慢?

可能是网络问题或依赖库版本冲突。尝试更换其他镜像源,如阿里云镜像:https://mirrors.aliyun.com/pypi/simple

如何恢复默认源?

修改配置文件,将 index-url 改为官方地址:

[global]
index-url = https://pypi.org/simple

或者使用命令行清除配置:

pip config unset global.index-url
遇到 SSL 证书验证失败?

可以通过添加 --trusted-host 参数解决:

pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
配置多个镜像源?

可以通过添加 extra-index-url 参数实现:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url = https://mirrors.aliyun.com/pypi/simple/

通过这些方法,开发者可以有效地配置国内 PyPI 镜像源,提高下载和安装 Python 包的速度。

 

相关文章:

  • IDEA Generate POJOs.groovy 踩坑小计 | 生成实体 |groovy报错
  • 数据库安装
  • 测试理论快速入门
  • 记录Linux安装mysql8
  • vue3页面html导出word文档
  • AI视频领域的DeepSeek—阿里万相2.1图生视频
  • [C语言日寄] 字符串操作函数的使用及其拓展
  • C/C++获取结构体成员的偏移量
  • 【CXX】5.2 extern “C++“
  • 4.2 使用说明:手册写作利器VNote的使用
  • 大白话html第十一章
  • I²C总线应用场景及1.8V与3.3V电压选择
  • Nano-GraphRAG复现——只使用Ollama,无需API Key
  • 质量属性场景描述
  • IO基础练习4
  • CogToolBlock和CogIDTool工具
  • ES时序数据库的性能优化
  • C++ Primer 拷贝、赋值与销毁
  • 如何改变怂怂懦弱的气质(2)
  • 记录一次利用条件索引优化接口性能的实践
  • 浙江美术馆馆长人民日报撰文:打开更辽阔的审美场域
  • 陈刚:推动良好政治生态和美好自然生态共生共优相得益彰
  • 视频丨歼-10CE首次实战大放异彩
  • 阳光保险拟设立私募证券投资基金,总规模200亿元
  • 词条数量大幅扩充,《辞海》第八版启动编纂
  • 霍步刚任辽宁沈阳市委书记