How to use pip (2014/1 version) ==================================
Previous pipの使い方 and say I wrote the article, this is and January of 2011, just three years ago . I have changed so much from now, so I would like to summarize it here again.
The pip version mentioned here is 1.5. If the version of your pip is old pip install -U pip as, please update.
Warning
Major changes : such as from pip 1.5 "pre" Ya "b" has been removed from the target of the package is the default in the search and installation that is attached to the version. Therefore, packages installed with less than 1.5 version of pip may not be included in 1.5.
--pre to quote, you can put these versions.
What is pip?
Pip is a package management system in Python.
Install pip
Tip
pipはcpythonの2.6, 2.7, 3.1, 3.2, 3.3, 3.4のバージョンをサポートしています。 Python 2.5 is no longer available from pip 1.3.1.
Tip
pip 1.5.1からsetuptoolsのインストールが要らなくなりました。get-pip.pyが自動的に入れてくれます。
get-pip.py to download. Please pay attention to security.
Run it with python. Sometimes sudo is necessary.
Code-Block .. :: None
% Python get-pip.py
Or use the package manager of the distribution.
% sudo apt-get install python-pip # debuan/ubuntu
% sudo yum install python-pip # fedora
Help
% pip help # 全体的なhelpを表示
% pip help install # installに関するhelpを表示
% pip help freeze # freezeに関するhelpを表示
Search pypi
pip is Python Package Index(pypi) https://pypi.python.org/pypi>` _ a near Ru package, you can search in the search command.
% pip search pycrypto
pycryptopp - Python wrappers for a few algorithms from theCrypto++ library
pycrypto - Cryptographic modules for Python.
INSTALLED: 2.6.1 (latest)
pycryptopan - A python implementation of Crypto-PAna ip anonymization algorithm
As indicated by INSTALLED, the already installed package will be displayed as such.
- --index <url>
- When searching other than pypi, specify the base URL.
install
Use install.
% pip install pycrypto
Automatically install freeze package
Later-described freeze the package list, which had been writing with the whole and install. The exported package list is just a text file, so you can easily edit it. Even those with dependencies are installed without permission, so it is okay if you leave as much as you need.
% pip freeze > packages_requirements.txt
(必要ならばファイルを編集)
% pip install -r packages_requirements.txt
(複数指定も可能)
% pip install -r basic_requirements.txt -r packages_requirements.txt
By the way, if you want to insert the latest version at the time you hit pip install, you can skip the version.
MarkupSafe
pycrypto
It should be noted that, -–no-deps to quote, exactly the same package and the package was written out list will be installed. This prevents dependencies from installing unexpected packages.
Set proxy
% pip install pycrypto --proxy=http://user@proxy.example.jp:8080
Tip
2014/07追記: "http"が必要になりました。
Install in user directory
In environments where there is no root, you can only install it in the user directory. To do so, add - user.
% pip install pycrypto --user
If you install with --user like this, it will be placed under ~ / .local /. If you do not pass PATH to ~ / .local / bin etc., so be careful.
Install a specific version
You can also specify the version and install it.
% pip install Flask==0.10.1
Please note that since the package file exported with freeze is in this format, the exported version will be installed as the name of freeze.
How to specify the version is more flexible and can do this.
% pip install 'Markdown<2.0'
In this case, if already installed version 2.0 or higher, uninstall it and install version satisfying <2.0.
Also,
% pip install 'Markdown>2.0,<2.0.3'
You can do it.
Install your local repository
You can install it directly from the repository at hand.
% pip install -e .
Install directly from Subversion / git / mercurial / bazaar
It can also be installed directly from a remote repository.
% pip install -e git+https://git.repo/some_pkg.git#egg=SomePackage # git
% pip install -e hg+https://hg.repo/some_pkg#egg=SomePackage # mercurial
% pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage # svn
% pip install -e git+https://git.repo/some_pkg.git@feature#egg=SomePackage # 'feature' ブランチから
# リポジトリのサブディレクトリからインストール
% pip install -e git+https://git.repo/some_repo.git@egg=subdir&subdirectory=subdir_path
Install directly from the archive file
It can be installed directly from tar.gz or zip file.
% pip install ./downloads/SomePackage-1.0.4.tar.gz
% pip install http://my.package.repo/SomePackage-1.0.4.zip
Try it without installing it
You may want to see what is downloaded. In that case, -d use the option.
% pip install pycrypto -d /tmp/
This downloads tar.gz of pycrypto below / tmp.
I want to install it again
-I (--ignore-installed) use.
% pip install pycrypto -I
I want to upgrade
If you are upgrading the once the packages installed, -U (--upgrade) use.
% pip install pycrypto -U
Install from other than pypi
You may want to install from a location other than pypi such as the local mirror environment.
Search and install from the specified location without searching from pypi.
% pip install --index-url http://my.package.repo/simple/ SomePackage
In addition to pypi, specify the location to search and install.
% pip install --extra-index-url http://my.package.repo/simple
Install it locally, from the directory where the file is located flat. --no-index to quote, do not search the index.
% pip install --no-index --find-links=file:///local/dir/ SomePackage
% pip install --no-index --find-links=/local/dir/ SomePackage
% pip install --no-index --find-links=relative/dir/ SomePackage
Install from wheel
You can install the wheel created with the wheel command described later.
% pip install --use-wheel --no-index --find-links=/tmp/wheelhouse pycrypto
I want to use Mirror
Mirror no longer exists. For more details, PEP 449 Please look at the
Show currently installed packages
Use list.
% pip list
ansible (1.4.2)
argparse (1.2.1)
ecdsa (0.10)
Flask (0.10.1)
httplib2 (0.8)
The frequently used options are as follows.
- -o
- Show updateable packages
- -u
- Show package with latest version
- -e
- Show package with install -e
- -l
- In the case of the virtualenv environment, do not display packages installed on the system
- --pre
- Also show beta version
Show packages currently installed for inclusion later
With Freeze, pip install -r in a format that can be installed together in, writes the packages that are currently installed.
% pip freeze > requirementx.txt
To uninstall
Use uninstall.
% pip uninstall pycrypto
By the way, if you add -y, answer yes to all questions. Sometimes useful, please be careful and use it.
I would like to specify requirements file
-r and remove them in bulk only files that began to write in the freeze using.
% pip uninstall -r requirements.txt
I want to know the details of the installed package
Use show.
% pip show pycrypto
- -f
- Displays all the files contained in the package.
Create wheel
Create a wheel. Wheel is a substitute for egg, it is a format for saving pre-built packages, and by using wheel you can save time and effort to compile each time. For more details, Wheelドキュメント Please look at.
The wheel package is required to execute the wheel command. Prior to pip install wheel and, please be sure that you install.
% pip wheel pycrypto # パッケージ名指定
% pip wheel -r requirements.txt # ファイル指定
% pip wheel hg+https://hg.repo/some_pkg # vcs指定
% pip wheel . # ローカル指定
% pip wheel hoge.tar.gz # アーカイブファイル指定
The default is wheelhouse will be made wheel file is created in the following directory called. Because it follows the dependence relationship, there are cases where multiple wheel files are created.
Configuration
Pip uses the following file as the setting file.
- UNIX type and Max OS X are $ HOME / .pip / pip.conf
- Windows% HOME% pip pip.ini
It is a description in ini format.
[global]
timeout = 60
index-url = http://download.zope.org/ppix
Alternatively, if you want to specify the install command
[install]
ignore-installed = true
no-dependencies = yes
find-links =
http://mirror1.example.com
http://mirror2.example.com
You can write. Of course you can write both global and install at the same time.
Environment variable
You can also use environment variables.
% export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"
You can capitalize option names like PIP_FIND_LINKS and PIP_DEFAULT_TIMEOUT.
Shell completion
She will write out a script for shell completion.
% pip completion --zsh >> ~/.zprofile
If you are still using bash, you can also use the following options
% pip completion --bash >> ~/.profile
Or you can directly eval without writing it out.
% eval "`pip completion --zsh`"