Linux下配置pip镜像源遇到的小坑

本文详细介绍了在Linux环境下,尤其是CentOS6.9和Python3.4版本中,为解决pip下载速度缓慢的问题,如何将pip镜像源更换为国内镜像。文章通过实例演示了非root用户和root用户在配置pip.conf文件时的注意事项,以及如何正确配置才能使换源生效。
部署运行你感兴趣的模型镜像

Linux下pip换源遇到的坑

#1 环境及需求

1.1 环境

CentOS 6.9
Python 3.4

#1.2 需求

pip镜像国外的下载速度慢,需要将pip镜像源换成国内镜像

#2 开始

#2.1 非root用户

在/home/用户名/目录下新建.pip/pip.conf文件

文件内容如下:

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

#2.2 使用

pip install get-time

打印的信息中,显示已经换源成功,但是非root用户没有修改文件的权限

[cox@799a3e499eed python2.6]$ pip install get-time
DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429).
Looking in indexes: http://pypi.douban.com/simple
Collecting get-time
Installing collected packages: get-time
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/lib/python3.4/site-packages/get_time'
Consider using the `--user` option or check the permissions.

20200105000053-image.png

切换root用户

su root
pip install get-time

下载成功,但是很慢,并没有使用国内的镜像源

[root@799a3e499eed python2.6]# pip install get-time
DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won’t be maintained after March 2019 (cf PEP 429).
Collecting get-time
Downloading https://files.pythonhosted.org/packages/6c/2c/881da0e98685d2b39596f198eaf11ff6582fde5eb403c52bf3f405a1128f/get-time-0.0.4.tar.gz
Building wheels for collected packages: get-time
Building wheel for get-time (setup.py) … done
Stored in directory: /root/.cache/pip/wheels/6c/9d/4e/58515015fcd0ec032405fd8ce96795aed16458edd1ca793532
Successfully built get-time
Installing collected packages: get-time
Successfully installed get-time-0.0.4

20200105000414-image.png

为什么没有root用户没有使用刚刚配置的国内的镜像源 ???

原来是因为配置的pip.conf文件存在/home/用户名/目录下,这样配置的镜像源只对指定的用户起作用, 使用root权限下载的时候,并不会走pip.conf文件,所以下载很慢

如何配置root用户额镜像源 ???

在~目录下新建.pip/pip.conf文件, 内容同上

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

使用root用户下载

20200105001045-image.png

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值