LoginSignup
1
1

More than 3 years have passed since last update.

【Windows】Pythonのpip

Last updated at Posted at 2018-12-31

はじめに

前回はPython2と3をインストールして、実行方法を確認した。今回はpipについてまとめる。なお、Python3をベースにする。

概要

pipとはPythonのパッケージ管理ツールである。Rubyなどと同様にPython人様が作成したPythonスクリプトを自分のスクリプトで利用できる。なお、pip自体もまたパッケージである。

パッケージをインストールするpipパッケージを導入するにはどうするか。答えはsetuptoolsパッケージをインストールし、easy_installコマンドを実行する。

Windowsのインストーラーだとデフォルトでsetuptoolsもpipも入った状態でPythonをインストールされる。(あるバージョンからデフォルトで入るようになったらしい。)

パッケージの確認

pip listでインストールされたパッケージが確認できる。

C:\Program Files (x86)\Python37-32\Scripts>pip list
Package    Version
---------- -------
pip        18.1
setuptools 40.6.2

パッケージの導入

今回はpython-dateutilを入れてみる。

Python標準のdatetimeモジュールを拡張します。月末を算出したり、「次の◯曜日」を算出したり、「当月の最終◯曜日」を算出したりすることができます。

C:\Program Files (x86)\Python37-32\Scripts>pip install python-dateutil
Collecting python-dateutil
  Using cached https://files.pythonhosted.org/packages/74/68/d87d9b36af36f44254a8d512cbfc48369103a3b9e474be9bdfe536abfc45/python_dateutil-2.7.5-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil
Successfully installed python-dateutil-2.7.5 six-1.12.0
C:\Program Files (x86)\Python37-32\Scripts>pip list
Package         Version
--------------- -------
pip             18.1
python-dateutil 2.7.5
setuptools      40.6.2
six             1.12.0

※管理者権限で実行

インストール単位

当然ながら、Python2には影響なし。

C:\Python27\Scripts>pip list --format=legacy
pip (9.0.3)
setuptools (39.0.1)
You are using pip version 9.0.3, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

まとめ

特に難しい話はなし。Pythonはシンプルで好感がもてるぞ。

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