インストール・設定
pipは、Pythonのパッケージ管理システムになります。 他にeasy_installもありますが、pipはeasy_installを置きかえるツールのようです。
インストール
CentOSでは、yumでインストールできます。
# yum install python-pip ・・・ ========================================================================================== Package Arch Version Repository Size ========================================================================================== Installing: python-pip noarch 0.8-1.el6 epel 178 k Installing for dependencies: python-setuptools noarch 0.6.10-3.el6 base 336 k Transaction Summary ========================================================================================== Install 2 Package(s) Total download size: 513 k Installed size: 2.2 M ・・・ ・・・ Downloading Packages: python-pip-0.8-1.el6.noarch.rpm | 178 kB 00:00 警告: rpmts_HdrFromFdno: ヘッダ V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 Importing GPG key 0x0608B895: Userid : EPEL (6) <epel@fedoraproject.org> Package: epel-release-6-6.noarch (@epel/6.2) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : python-pip-0.8-1.el6.noarch 1/1 Installed: python-pip.noarch 0:0.8-1.el6 Complete!
pipはeasy_installからインストールすることもできます。 その場合、ますeasy_installが入っているpython-setuptoolsをインストールします。 その後、easy_installからpipをインストールします。
# yum install python-setuptools # easy_install pip
CentOS6の場合、インストールが成功すると、pip-pythonがインストールされているはずです。
# which pip-python /usr/bin/pip-python注意 CentOSでyumでインストールすると、コマンドはpipでなく、pip-pythonになっています。
pipのアップグレード
pythonをインストール後、pipで検索すると以下のようなエラーになりました。 pipのバージョンが古いそうです。
$ pip search django
Exception:
Traceback (most recent call last):
File "/root/.pyenv/versions/3.4.5/lib/python3.4/site-packages/pip/basecommand.py", line 209, in main
...
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
そのため、メッセージに書かれている以下のコマンドを実行してpipを更新します。
pip install --upgrade pip
実行すると以下のようにアップグレードします。。
$ pip install --upgrade pip
Collecting pip
Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
47% |???????????????? | 573kB 22.9MB/s eta 0:00:0 48% |???????????????? | 583kB 26.3MB/s eta 0:00:0 49% |???????????????? | 593kB 31.6MB/s eta 0:00:0 50% |????????????????? | 604kB 100% |????????????????????????????????| 1.2MB 1.3MB/s
Installing collected packages: pip
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Successfully uninstalled pip-8.1.1
Successfully installed pip-8.1.2
使用方法
モジュールのインストール
モジュールをインストールは、pipのinstallコマンドを使います。
$ pip install numpy
Collecting numpy
Downloading https://files.pythonhosted.org/packages/ff/7f/9d804d2348471c67a7d8b5f84f9bc59fd1cefa148986f2b74552f8573555/numpy-1.15.4-cp36-cp36m-manylinux1_x86_64.whl (13.9MBimport numpy as np
)
100% |████████████████████████████████| 13.9MB 2.5MB/s
Installing collected packages: numpy
Successfully installed numpy-1.15.4
インストール済みモジュールの確認
pipのlistコマンドでインストール済みモジュールが確認できます。
$ pip list Package Version ---------- ------- pip 18.1 setuptools 28.8.0
help
オプションの-hでヘルプが表示されせて、オプションが確認できます。
# pip help
Usage: pip COMMAND [OPTIONS]
Options:
--version show program's version number and exit
-h, --help Show help
-E DIR, --environment=DIR
virtualenv environment to run pip in (either give the
interpreter or the environment base directory)
-s, --enable-site-packages
Include site-packages in virtualenv if one is to be
created. Ignored if --environment is not used or the
virtualenv already exists.
-v, --verbose Give more output
-q, --quiet Give less output
--log=FILENAME Log file where a complete (maximum verbosity) record
will be kept
--proxy=PROXY Specify a proxy in the form
user:passwd@proxy.server:port. Note that the
user:password@ is optional and required only if you
are behind an authenticated proxy. If you provide
user@proxy.server:port then you will be prompted for a
password.
--timeout=SECONDS, --default-timeout=SECONDS
Set the socket timeout (default 15 seconds)
Commands available:
bundle: Create pybundles (archives containing multiple packages)
freeze: Output all currently installed packages (exact versions) to stdout
help: Show available commands
install: Install packages
search: Search PyPI
uninstall: Uninstall packages
unzip: Unzip individual packages
zip: Zip individual packages