Ubuntu18.04下 pip3 install django報錯時解決方法

在Ubuntu系統下安裝django時,終端下輸入:

root@ubuntu:/home/fanzhh# pip3 install django

出現如下錯誤:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting django
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/django/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/django/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/django/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/django/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/django/
  Could not fetch URL https://pypi.org/simple/django/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/django/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  Could not find a version that satisfies the requirement django (from versions: )
No matching distribution found for django
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

原來是下載速度太慢了,所以就切換到國內鏡像:

pip國內的一些鏡像

阿里雲 http://mirrors.aliyun.com/pypi/simple/
  中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
  豆瓣(douban) http://pypi.douban.com/simple/
  清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
  中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/

修改原方法:
可以在使用pip的時候在後面加上-i參數,指定pip源

pip3 install django -i http://pypi.douban.com/simple

很快就下載成功了

如需指定需要安裝的庫requirements.txt

pip3 install -r “/home/admin/$APP_NAME/conf/requirements.txt” -i “http://mirrors.aliyun.com/pypi/simple” --trusted-host “mirrors.aliyun.com” && \ #通過阿里雲鏡像安裝三方庫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章