Pip (package manager)
Package management system for Python
- 3 min read
- 3 chapters
Related on Lably
Through Python (programming language), Python Package Index and HTTP
Most distributions of Python come with pip preinstalled. Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default.
History
First introduced as pyinstall in 2008 by Ian Bicking (the creator of the virtualenv package) as an alternative to easy install, pip was chosen as the new name from one of several suggestions that the creator received on his blog post. According to Bicking himself, the name is a recursive acronym for "Pip Installs Packages". In 2011, the Python Packaging Authority (PyPA) was created to take over the maintenance of pip and virtualenv from Bicking, led by Carl Meyer, Brian Rosner, and Jannis Leidel.
With the release of pip version 6.0 (2014-12-22), the version naming process was changed to have version in X.Y format and drop the preceding 1 from the version label.
Sign in to keep reading
2 more chapters are free with a Lably account.
Command-line interface
Pip's command-line interface allows the install of Python packages by issuing a command:
pip install some-package-name
Users can also remove the package by issuing a command:
pip uninstall some-package-name
pip has a feature to manage full lists of packages and corresponding version numbers, possible through a "requirements" file. This permits the efficient re-creation of an entire group of packages in a separate environment (e.g. another computer) or virtual environment. This can be achieved with a properly formatted file and the following command, where requirements.txt is the name of the file:
pip install -r requirements.txt
To install some package for a specific Python version, pip provides the following command, where ${version} is replaced by 2, 3, 3.4, etc.:
pip${version} install some-package-nameUsing pyproject.toml files
Pip provides a way to install local projects with the use of a pyproject.toml file. This method requires the project to have the following file structure:
example_project/ ├── exampleproject/ Python package with source code. | ├── __init__.py Makes the folder a package. |<span typeof="mw:Entity" id="mwcg"> </span> └── example.py Example module. └── README.md README with info of the project.
Within this structure, users can add pyproject.toml to the root of the project (i.e. example_project for above structure) with the following content:
<span id="mweQ"></span><span class="linenos" data-line="1" id="mweg"></span><span class="k" id="mwew">[build-system]</span> <span class="linenos" data-line="2" id="mwfA"></span><span class="n" id="mwfQ">requires</span><span class="w" id="mwfg"> </span><span class="o" id="mwfw">=</span><span class="w" id="mwgA"> </span><span class="p" id="mwgQ">[</span><span class="s2" id="mwgg">"setuptools>=61.0.0"</span><span class="p" id="mwgw">]</span> <span class="linenos" data-line="3" id="mwhA"></span><span class="n" id="mwhQ">build-backend</span><span class="w" id="mwhg"> </span><span class="o" id="mwhw">=</span><span class="w" id="mwiA"> </span><span class="s2" id="mwiQ">"setuptools.build_meta"</span> <span class="linenos" data-line="4" id="mwig"></span> <span class="linenos" data-line="5" id="mwiw"></span><span class="k" id="mwjA">[project]</span> <span class="linenos" data-line="6" id="mwjQ"></span><span class="n" id="mwjg">name</span><span class="w" id="mwjw"> </span><span class="o" id="mwkA">=</span><span class="w" id="mwkQ"> </span><span class="s2" id="mwkg">"example_project"</span> <span class="linenos" data-line="7" id="mwkw"></span><span class="n" id="mwlA">version</span><span class="w" id="mwlQ"> </span><span class="o" id="mwlg">=</span><span class="w" id="mwlw"> </span><span class="s2" id="mwmA">"1.0.0"</span> <span class="linenos" data-line="8" id="mwmQ"></span><span class="n" id="mwmg">description</span><span class="w" id="mwmw"> </span><span class="o" id="mwnA">=</span><span class="w" id="mwnQ"> </span><span class="s2" id="mwng">"An example project."</span> <span class="linenos" data-line="9" id="mwnw"></span><span class="n" id="mwoA">readme</span><span class="w" id="mwoQ"> </span><span class="o" id="mwog">=</span><span class="w" id="mwow"> </span><span class="s2" id="mwpA">"README.md"</span> <span class="linenos" data-line="10" id="mwpQ"></span><span class="n" id="mwpg">requires-python</span><span class="w" id="mwpw"> </span><span class="o" id="mwqA">=</span><span class="w" id="mwqQ"> </span><span class="s2" id="mwqg">">=3.6"</span> <span class="linenos" data-line="11" id="mwqw"></span><span class="n" id="mwrA">license-files</span><span class="w" id="mwrQ"> </span><span class="o" id="mwrg">=</span><span class="w" id="mwrw"> </span><span class="p" id="mwsA">[</span><span class="s2" id="mwsQ">"LICENSE"</span><span class="p" id="mwsg">]</span> <span class="linenos" data-line="12" id="mwsw"></span><span class="n" id="mwtA">dependencies</span><span class="w" id="mwtQ"> </span><span class="o" id="mwtg">=</span><span class="w" id="mwtw"> </span><span class="p" id="mwuA">[]</span>
After this, pip can install this custom project by running the following command, from the project root directory: pip install -e ..
Custom repository
Besides the default Python Package Index (PyPI) repository, pip supports custom repositories also. Such repositories can be located on a Hypertext Transfer Protocol HTTP(s) URL, or on a file system.
A custom repository can be specified using the -i or --index-url option, thusly:
pip install -i <span typeof="mw:Nowiki" id="mwyA">https://your-custom-repo/simple</span> <span class="nowrap" about="#mwt81" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"angbr","href":"./Template:Angbr"},"params":{"1":{"wt":"package name"}},"i":0}}]}' id="mwyQ"><span typeof="mw:Entity">⟨</span>package name<span typeof="mw:Entity">⟩</span></span>or with a filesystem:
pip install -i /path/to/your/custom-repo/simple <span class="nowrap" about="#mwt82" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"angbr","href":"./Template:Angbr"},"params":{"1":{"wt":"package name"}},"i":0}}]}' id="mwzA"><span typeof="mw:Entity">⟨</span>package name<span typeof="mw:Entity">⟩</span></span>
