takaya030の備忘録

PHP、Laravel、Docker などの話がメインです

Windows版 python で pip の upgrade に失敗する

検証環境

Windows10 Home Edition
Python 2.7.6

発生したトラブルについて

C:\>pip list
  .
  .
pip (8.1.1)
  .
  .
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

上記の指示通り upgrade したらエラーが発生

C:\>python -m pip install --upgrade pip
C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\requests\packages\urllib3\util\ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\requests\packages\urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 764kB/s
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
  Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\basecommand.py", line 209, in main
    status = self.run(options, args)
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\commands\install.py", line 317, in run
    prefix=options.prefix_path,
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\req\req_set.py", line 732, in install
    **kwargs
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\req\req_install.py", line 835, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\req\req_install.py", line 1030, in move_wheel_files
    isolated=self.isolated,
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\wheel.py", line 461, in move_wheel_files
    generated.extend(maker.make(spec))
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\distlib\scripts.py", line 372, in make
    self._make_script(entry, filenames, options=options)
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\distlib\scripts.py", line 276, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\distlib\scripts.py", line 212, in _write_script
    launcher = self._get_launcher('t')
  File "C:\bin\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\distlib\scripts.py", line 351, in _get_launcher
    result = finder(distlib_package).find(name).bytes
AttributeError: 'NoneType' object has no attribute 'bytes'
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

試しにもう一度コマンド入力してみたらアップグレード済みと出る

C:\>python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\bin\python27\lib\site-packages

しかし "pip list" で確認するとアップグレードに失敗している模様

C:\>pip list
  .
  .
pip (8.1.1)
  .
  .
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

解決方法

"--force-reinstall" オプションをつけて再度アップグレードしたら直りました

C:\>python -m pip install --force-reinstall --upgrade pip
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-9.0.1

C:\>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
  .
  .
pip (9.0.1)
  .
  .