pip

提供: Python入門
移動: 案内検索
スポンサーリンク

pip とは、Pythonパッケージインストーラで、パッケージ管理システムです。

読み方

pip
ぴーあいぴー

概要

pipコマンドを使用して、Pythonパッケージを簡単にインストールしたり、アンインストールしたりできます。

インストール

Ubuntu

$ sudo apt install python-pip

FreeBSD の場合

sudo pkg install py27-pip

実行例

コマンドラインオプション

Usage:   
  pip <command> [options]
 
Commands:
  install                     Install packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  zip                         DEPRECATED. Zip individual packages.
  unzip                       DEPRECATED. Unzip individual packages.
  bundle                      DEPRECATED. Create pybundles.
  help                        Show help for commands.
 
General Options:
  -h, --help                  Show help.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output.
  --log-file <path>           Path to a verbose non-appending log, that only
  logs failures. This log is active by default at /home/kaworu/.pip/pip.log.
  --log <path>                Path to a verbose appending log. This log is inactive by default.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --cert <path>               Path to alternate CA bundle.

エラー

ImportError: cannot import name IncompleteRead

エラーメッセージ

Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 351, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2363, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2088, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead

解決方法

$ sudo easy_install -U pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 6.0.8
Downloading
https://pypi.python.org/packages/source/p/pip/pip-6.0.8.tar.gz#md5=2332e6f97e75ded3bddde0ced01dbda3
Processing pip-6.0.8.tar.gz
Writing /tmp/easy_install-ZajvEQ/pip-6.0.8/setup.cfg
Running pip-6.0.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ZajvEQ/pip-6.0.8/egg-dist-tmp-bqYMTz
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 6.0.8 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
 
Installed /usr/local/lib/python2.7/dist-packages/pip-6.0.8-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

python setup.py egg_info

エラー

インストールが失敗することがあります。

sudo pip install numpy
Collecting numpy
  Downloading numpy-1.9.1.tar.gz (4.0MB)
    100% |################################| 4.0MB 50kB/s
    Running from numpy source directory.
    /usr/local/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown
    distribution option: 'test_suite'
      warnings.warn(msg)
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help
    error: invalid command 'egg_info'
    Complete output from command python setup.py egg_info:
    Running from numpy source directory.
 
    /usr/local/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown
    distribution option: 'test_suite'
 
      warnings.warn(msg)
 
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
 
       or: -c --help [cmd1 cmd2 ...]
 
       or: -c --help-commands
 
       or: -c cmd --help
 
 
 
    error: invalid command 'egg_info'
 
    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in
    /tmp/pip-build-oNX6VD/numpy

解決方法

setuptoolsをアップデートすることで解消できました。

pip install --upgrade setuptools

関連項目




スポンサーリンク