pip 版本问题导致 pip install Django 失败的解决方法

问题描述:kubuntu 17.04 通过 pip 安装 Django ,由于 pip 版本问题导致安装失败,参考stackoverflow上的解决方法搞定该问题。

https://stackoverflow.com/questions/37495375/python-pip-install-throws-typeerror-unsupported-operand-types-for-retry

Ubuntu comes with a version of PIP from precambrian and that's how you have to upgrade it if you do not want to spend hours and hours debugging pip related issues.

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

As you observed I included information for both Python 2.x and 3.x


(ll_env) dechao@x230:~/my_python/learning_log$ pip install Django
Collecting Django
Exception:
Traceback (most recent call last):                                                                  
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main                                                                             
    status = self.run(options, args)                                                                
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/commands/install.py", line 353, in run                                                                         
    wb.build(autobuilding=True)                                                                     
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/wheel.py", line 749, in build                                                                                  
    self.requirement_set.prepare_files(self.finder)                                                 
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files                                                                    
    ignore_dependencies=self.ignore_dependencies))                                                  
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/req/req_set.py", line 554, in _prepare_file                                                                    
    require_hashes                                                                                  
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/req/req_install.py", line 278, in populate_link                                                                
    self.link = finder.find_requirement(self, upgrade)                                              
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/index.py", line 465, in find_requirement                                                                       
    all_candidates = self.find_all_candidates(req.name)                                             
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/index.py", line 423, in find_all_candidates                                                                    
    for page in self._get_pages(url_locations, project_name):                                       
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/index.py", line 568, in _get_pages                                                                             
    page = self._get_page(location)                                                                 
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/index.py", line 683, in _get_page                                                                              
    return HTMLPage.get_page(link, session=self.session)                                            
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/index.py", line 792, in get_page                                                                               
    "Cache-Control": "max-age=600",                                                                 
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 501, in get                                                     
    return self.request('GET', url, **kwargs)                                                       
  File "/home/dechao/my_python/learning_log/ll_env/local/lib/python2.7/site-packages/pip/download.py", line 386, in request                                                                             
    return super(PipSession, self).request(method, url, *args, **kwargs)                            
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 488, in request                                                 
    resp = self.send(prep, **send_kwargs)                                                           
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 609, in send                                                    
    r = adapter.send(request, **kwargs)                                                             
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 47, in send                                              
    resp = super(CacheControlAdapter, self).send(request, **kw)                                     
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/adapters.py", line 423, in send                                                    
    timeout=timeout                                                                                 
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 643, in urlopen                                             
    _stacktrace=sys.exc_info()[2])                                                                  
  File "/home/dechao/my_python/learning_log/ll_env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 315, in increment                                               
    total -= 1                                                                                      
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

=====

(ll_env)dechao@x230:~/my_python/learning_log$ sudo apt-get remove python-pip
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  libpython-all-dev linux-headers-4.10.0-19 linux-headers-4.10.0-19-generic linux-headers-4.10.0-22
  linux-headers-4.10.0-22-generic linux-image-4.10.0-19-generic linux-image-4.10.0-22-generic linux-image-extra-4.10.0-19-generic
  linux-image-extra-4.10.0-22-generic python-all python-all-dev python-cffi-backend python-cryptography python-enum34 python-idna
  python-ipaddress python-keyring python-keyrings.alt python-pyasn1 python-secretstorage python-six python-wheel
使用'sudo apt autoremove'来卸载它(它们)。
下列软件包将被【卸载】:
  python-pip
升级了 0 个软件包,新安装了 0 个软件包,要卸载 1 个软件包,有 0 个软件包未被升级。
解压缩后将会空出 671 kB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 285591 个文件和目录。)
正在卸载 python-pip (9.0.1-2) ...
正在处理用于 man-db (2.7.6.1-2) 的触发器 ...

=====

(ll_env)dechao@x230:~/my_python/learning_log$ wget https://bootstrap.pypa.io/get-pip.py
--2017-07-10 09:43:34--  https://bootstrap.pypa.io/get-pip.py
正在解析主机 bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.72.175
正在连接 bootstrap.pypa.io (bootstrap.pypa.io)|151.101.72.175|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 1595408 (1.5M) [text/x-python]
正在保存至: “get-pip.py”

get-pip.py                       100%[==========================================================>]   1.52M   426KB/s    in 3.7s    

2017-07-10 09:43:38 (426 KB/s) - 已保存 “get-pip.py” [1595408/1595408])

=====

(ll_env)dechao@x230:~/my_python/learning_log$ sudo python get-pip.py
The directory '/home/dechao/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.               
The directory '/home/dechao/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 343kB/s
Installing collected packages: pip
Successfully installed pip-9.0.1

=====

(ll_env) dechao@x230:~/my_python/learning_log$ pip install Django
Collecting Django
  Using cached Django-1.11.3-py2.py3-none-any.whl
Collecting pytz (from Django)
  Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, Django
Successfully installed Django-1.11.3 pytz-2017.2


你可能感兴趣的:(Python,学习杂记)