Linux下配置pip镜像源遇到的小坑 - Go语言中文社区

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


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

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/Coxhuang/article/details/103839223
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢