言葉にできるは武器なるらしい

言葉に文字に残していきます何事も。いつかきっと誰かの役に立つはずだから。

pipのインストール方法

pythonのバージョンを確認したところ 2.7.10が入っており、調べたところ、2.7.9以降にはpipは自動的に入っているという 情報があったが、pipのバージョンを確認すると「そんなコマンドはねぇ」と言われたので どうやらpipは入ってい無いようだ。


XXXXX$ python --version
Python 2.7.10

XXXXX$ pip -V
-bash: pip: command not found

ということで、pipのインストール方法を調べたところ 「sudo easy_install pip」こんな簡単にインストールできるようだ。 と思って実行してみたら↓な感じでダウンロードに失敗しているようだ。

【pipのインストール方法の失敗例】


XXXXX$ sudo easy_install pip
Password:
Searching for pip
Reading https://pypi.python.org/simple/pip/
Download error on https://pypi.python.org/simple/pip/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

別の方法で試したら行けたのでこちらが成功例

【pipのインストール方法の成功例】

まずはこのコマンドでpipのダウンロード


XXXXX$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1622k 100 1622k 0 0 1762k 0 --:--:-- --:--:-- --:--:-- 1761k

次にインストールします。


XXXXX$ python get-pip.py
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 5.2MB/s 
Collecting wheel
Downloading https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: pip, wheel
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'
Consider using the `--user` option or check the permissions.

これは失敗。 編集権限がなかったようで、「sudo」をつけたら行けました。

 

【pipのインストール方法の成功例】


XXXXX$ sudo python get-pip.py
Password:
The directory '/Users/ryotaroakiba/Library/Caches/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 '/Users/ryotaroakiba/Library/Caches/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 https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 9.8MB/s 
Collecting wheel
Downloading https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: pip, wheel
Successfully installed pip-18.1 wheel-0.32.3

やっとインストール完了。