设置pip/pyenv国内加速源

使用方式一(临时):

pip install 安装的模块名 -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com

会从指定的镜像地址安装模块

使用方式二(永久):

Linux:

在~目录创建.pip/pip.conf

cd ~
mkdir .pip
cd .pip
vim pip.conf

在打开的pip.conf中加入,wq保存退出即可

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

Windows:

新建文件C:\user/用户名/pip/pip.ini

pip.ini,加入

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

Docker:

Dockerfile文件中增加以下配置:

# Set pip repolist
RUN mkdir /root/.pip
COPY pip.conf /root/.pip/

创建pip.conf,打开pip.conf,加入

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

设置pyenv加速,比如安装Python 3.7.9
从阿里云下载Python
wget https://npm.taobao.org/mirrors/python/3.9.8/Python-3.9.8.tar.xz -P ~/.pyenv/cache
再次安装,可以看到命令行窗口打印内容更改为Installing,解决下载速度慢的问题。

pyenv install 3.9.8

参考:
https://www.kancloud.cn/studyforever/python_1/1986614

[Haima的博客] http://www.cnblogs.com/haima/
原文地址:https://www.cnblogs.com/haima/p/15536558.html