LoginSignup
1
1

More than 3 years have passed since last update.

【Python】pipコマンドのセットアップとライブラリのインストール方法

Posted at

pipコマンドとは

pipの正式名称は、Pip Install Packagesで、パッケージ管理システムです。
Python2.7.9以降とPython3.4以降にデフォルトで付属されており、

PyPI(Python Package Index)に登録されているwheel形式のPython外部パッケージ
をpipを使用することで、インストールできます。

  • wheel形式:Pythonのパッケージの形式(フォーマット)。 実態はzip形式のアーカイブで、PEP427で定義されている

pipのセットアップ

bash_profileにpythonコマンドのPATHを通しておく

# vimでbash_profileを編集
$ vi ~/.bash_profile

# insertモードで下記を追加(※versionは任意)
export PATH=$PATH:/Users/username/Library/Python/3.8/bin

# vimを抜ける => escを押してから:wqで保存

# bash_profileの更新を反映
$ source ~/.bash_profile

pipのインストール

# get-pip.pyのダウンロード。任意のディレクトリに保存
$ mkdir ./pip
$ cd pip
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

# 保存したディレクトリで実行
$ python get-pip.py

# インストールの確認(version確認)
$ pip -V

ライブラリのインストール

試しに、requestsパッケージをインストールしてみます。
(2021/03/30時点)

# カレントディレクトリにrequestsをインストール
$ pip install requests -t .

Collecting requests
  Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 2.2 MB/s 
Collecting certifi>=2017.4.17
  Using cached certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Collecting chardet<5,>=3.0.2
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     |████████████████████████████████| 178 kB 3.3 MB/s 
Collecting idna<3,>=2.5
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.4-py2.py3-none-any.whl (153 kB)
     |████████████████████████████████| 153 kB 1.3 MB/s 
Installing collected packages: urllib3, idna, chardet, certifi, requests
Successfully installed certifi-2020.12.5 chardet-4.0.0 idna-2.10 requests-2.25.1 urllib3-1.26.4

まとめ

ハマったところは

  • 事前にpythonのPATHを通しておく必要があった
  • get-pip.pyを自分でダウンロードして、ダウンロードしたディレクトリでその展開が必要だった

pipって響き、なんかかわいい✨

以上、ありがとうございました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1