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

發佈了112 篇原創文章 · 獲贊 36 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章