python | pip 使用豆瓣源


pip 使用豆瓣源

pip 使用豆瓣源
由於pip 默認使用Python的官方源pypi.python.org/pypi,導致我們經常使用pip裝包時速度過慢或者無法安裝(請求超時)等問題,
所以國內用戶建議使用pip 國內源。
目前常用的 pip 國內源有:
豆瓣:http://pypi.douban.com/simple/(推薦)
提示:Python3默認已經再帶pip
如果沒有安裝pip包,可以官網下載get-pip.py文件,然后執行安裝命令:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py -i http://pypi.douban.com --trusted-host pypi.douban.com
 
下面我們以使用豆瓣源為例來講解,同時豆瓣源已經支持http 和 https 兩種協議。
方式1:使用pip下載時指定源
pip install tornado -i http://pypi.douban.com/simple/ trusted-host =  http://pypi.douban.com
pip install -r req.txt -i  http://pypi.douban.com/simple/
參數說明:
-i :指定pip源
trusted-host :說明可信的pip源
方式2:創建配置文件,定義pip安裝源
Linux方法:
================================================
Linux:
$HOME/.config/pip/pip.conf 
或者 
$HOME/.pip/pip.conf(推薦)
================================================
mac:
$HOME/Library/Application Support/pip/pip.conf 
或者 
$HOME/.pip/pip.conf
================================================
1)創建 ~/.pip目錄 ,新建 ~/.pip/pip.conf文件,內容如下:
[global]
timeout =6000
index-url =http://pypi.douban.com/simple/
[install]
use-mirrors =true 
mirrors =http://pypi.douban.com/simple/ 
trusted-host =pypi.douban.com
也可以簡寫為:
[global]
index-url =http://pypi.douban.com/simple/
[install]
trusted-host =pypi.douban.com
2)直接使用pip安裝
Windows 10方法:
1)新建 %HOME%\pip\pip.ini 文件,內容如下:
[global] 
timeout = 6000
index-url = http://pypi.douban.com/simple
trusted-host = http://pypi.douban.com
2)直接使用pip安裝
另外, 使用setup.py安裝依賴庫, 還是會從默認的http://pypi.python.org下載, 解決方案如下:
編輯 ~/.pydistutils.cfg 文件,內容如下:
[easy_install]
timeout = 60
index_url = https://pypi.douban.com/simple
 
歡迎關注學創英才公眾號:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM