pip换源

由于pip 默认使用Python的官方源pypi.python.org/pypi,导致我们经常使用pip装包时速度过慢或者无法安装(请求超时)等问题,所以国内用户建议使用pip 国内源。

目前常用的 pip 国内源有:

豆瓣:http://pypi.douban.com/simple/(推荐)

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

提示:Python3默认已经再带pip 如果没有安装pip包,可以官网下载get-pip.py文件,然后执行安装命令:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

python get-pip.py -i http://pypi.douban.com --trusted-host pypi.douban.com

下面我们以使用豆瓣源为例来讲解,同时豆瓣源已经支持http 和 https 两种协议。

方式1:使用pip下载时指定源

pip install tornado -i http://pypi.douban.com/simple/ trusted-host = [http://pypi.douban.com](http://pypi.douban.com/)

pip install -r requirements.txt -i http://pypi.douban.com/simple/

参数说明:

-i :指定pip源

trusted-host :说明可信的pip源

方式2:创建配置文件,定义pip安装源

Linux 方法:新建$HOME/.config/pip/pip.conf 或者 $HOME/.pip/pip.conf 文件

mac 方法:新建$HOME/Library/Application Support/pip/pip.conf 或者 $HOME/.pip/pip.conf文件

Windows 方法:新建 %HOME%\pip\pip.ini 文件

Linux or mac 文件内容如下:

[global]

timeout =6000

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

[install]

use-mirrors =true

mirrors =http://pypi.douban.com/simple/

trusted-host =pypi.douban.com

Windows 文件内容如下:

[global]

timeout = 6000

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

trusted-host =http://pypi.douban.com

posted @   藍色的泡泡  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示