pip国内镜像源配置

pip国内镜像源配置python 从国外源下载安装包 会特别慢 还会经常出现下载失败的情况 所以我们要从国内源下载安装包

大家好,欢迎来到IT知识分享网。

python从国外源下载安装包,会特别慢,还会经常出现下载失败的情况,所以我们要从国内源下载安装包。

一、常用pip软件源

1.1  pip官方软件源 

官方源 https://pypi.python.org/simple

1.2  常用国内镜像源 

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

1.3 临时指定软件源

通常来讲,如果想要手动指定临时软件源来安装软件的话,可是使用如下格式
    pip install -i xx(其中xx是指定的源ip地址)

例如,使用豆瓣源来安装jieba包
    pip install jieba -i https://pypi.douban.com/simple

1.4  永久指定软件源

1.4.1  针对当前用户

在UNIX系统中默认的配置文件是: $HOME/.config/pip/pip.conf。 which respects the XDG_CONFIG_HOME environment variable。
在macOS系统中配置文件是:$HOME/Library/Application Support/pip/pip.conf。在$HOME/Library/Application Support/pip/目录不存在的情况下,也可是是$HOME/.config/pip/pip.conf。
在Windows系统中默认的配置文件是:%APPDATA%\pip\pip.ini。

pip也支持经典的每个用户一个配置文件的方式,具体的位置是:

Unix 和 macOS 配置文件: $HOME/.pip/pip.conf
Windows t配置文件: %HOME%\pip\pip.ini
当然,也可是使用环境变量PIP_CONFIG_FILE来自定义配置文件位置

1.4.2  针对虚拟环境

1.4.3  针对整个系统

Unix 配置文件 /etc/pip.conf. 当然也可以是一个任何路径下的 “pip” 子目录,然后通过环境变量XDG_CONFIG_DIRS来指定, 例如/etc/xdg/pip/pip.conf.
macOS 配置文件: /Library/Application Support/pip/pip.conf
Windows XP 配置文件: C:\Documents and Settings\All Users\Application Data\pip\pip.ini
Windows 7 及其更高版本的配置文件是隐藏的, 就可以在C:\ProgramData\pip\pip.ini中写入
Site-wide configuration is not supported on Windows Vista

1.4.4  配置文件的级别

If multiple configuration files are found by pip then they are combined in the following order:

The site-wide file is read
The per-user file is read
The virtualenv-specific file is read

Each file read overrides any values read from previous files, so if the global timeout is specified in both the site-wide file and the per-user file then the latter value will be used.

1.5  pip多镜像源配置文件内容

[global]
    timeout=60
    index-url=https://pypi.douban.com/simple
    extra-index-url=https://mirrors.aliyun.com/pypi/simple/
            https://pypi.tuna.tsinghua.edu.cn/simple/
            https://pypi.mirrors.ustc.edu.cn/simple/
    [install]
    trusted-host=pypi.douban.com
     mirrors.aliyun.com
     pypi.tuna.tsinghua.edu.cn
     pypi.mirrors.ustc.edu.cn
    [freeze]
    timeout = 10

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/146826.html

(0)
上一篇 2025-04-11 22:15
下一篇 2025-04-11 22:20

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信