前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux下配置pip镜像源遇到的小坑

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

作者头像
Autooooooo
发布2020-11-09 10:18:13
2.2K0
发布2020-11-09 10:18:13
举报
文章被收录于专栏:Coxhuang

Linux下pip换源遇到的坑

#1 环境及需求

1.1 环境

代码语言:javascript
复制
CentOS 6.9
Python 3.4

#1.2 需求

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

#2 开始

#2.1 非root用户

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

文件内容如下:

代码语言:javascript
复制
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

#2.2 使用

代码语言:javascript
复制
pip install get-time

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

代码语言:javascript
复制
[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
20200105000053-image.png

切换root用户

代码语言:javascript
复制
su root
代码语言:javascript
复制
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
20200105000414-image.png

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

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

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

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

代码语言:javascript
复制
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

使用root用户下载

20200105001045-image.png
20200105001045-image.png
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/01/05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Linux下pip换源遇到的坑
  • #1 环境及需求
    • 1.1 环境
      • #1.2 需求
      • #2 开始
        • #2.1 非root用户
          • #2.2 使用
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档