python包管理利器-更换安装源


前言

使用python 安装第三方包的时候,总是会因为网络问题,导致某些依赖包安装失败
今天来看一下各种安装工具(pip,pipx,poetry,easy_install)怎么更换安装源

国内的一些镜像

阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 
豆瓣(douban) http://pypi.douban.com/simple/ 
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

PIP 更换国内安装源

临时使用

可以在使用pip的时候在后面加上-i参数,指定pip源

pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

永久修改

linux

修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

# ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

windows

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,在pip 目录下新建文件pip.ini,内容如下

或者按照网友的建议:win+R 打开用户目录%HOMEPATH%,在此目录下创建 pip 文件夹,在 pip 目录下创建 pip.ini 文件, 内容如下

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

easy_install更换国内安装源

创建配置文件:
Windows下是在: ~\pydistutils.cfg
Linux下是在: $HOME/.pydistutils.cfg

内容

[easy_install]
index-url=http://pypi.douban.com/simple

poetry 更换国内安装源

poetry 使用的是配置文件安装内容,因此在配置文件中加入下面的内容

[[tool.poetry.source]]
name = "tsinghua"
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/"
default = true  # 添加一个 default 参数, 使 poetry 的默认回调行为都调用到这个清华镜像上.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM