Pip: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(25 intermediate revisions by the same user not shown)
Line 6: Line 6:
* [[Python]]
* [[Python]]
* [[Python Package Managers#Package_Managers|Python Package Managers]]
* [[Python Package Managers#Package_Managers|Python Package Managers]]
* [[pip-compile]]


=Overview=
=Overview=
Line 22: Line 23:
</syntaxhighlight>
</syntaxhighlight>


=<span id='requirements.txt'></span><tt>requirements.txt</tt> File=
=<span id='requirements.txt'></span><span id=Example'></span><span id='Fine_Tuning_Requirements'></span><span id='Chaining_Requirement_Files'></span><span id='How_to_Lock_Down_Direct_and_Transitive_Dependencies'></span><tt>requirements.txt</tt> File=
The <code>requirements.txt</code> allows you to specify which packages and versions should be installed. Typically, the <code>requirements.txt</code> file is located in the root of the project. The  <code>requirements.txt</code> file can be generated with <code>[[#Freeze_Dependencies|pip freeze]]</code> command.
{{Internal|requirements.txt|requirements.txt}}
==Example==
<syntaxhighlight lang='text'>
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
scipy==0.13.0b1
six==1.4.1
virtualenv==16.3.0
</syntaxhighlight>


=Version=
=Version=
Line 49: Line 40:
pip show <package-name>
pip show <package-name>
</syntaxhighlight>
</syntaxhighlight>
==<span id='search'></span>Searching Packages==
The search command looks for packages published to [[Python Language Modularization#PyPI|PyPI]].
<syntaxhighlight lang='bash'>
pip search <query>
</syntaxhighlight>
==Install a Package==
==Install a Package==
{{External|https://pip.pypa.io/en/stable/cli/pip_install/}}
<syntaxhighlight lang='bash'>
pip install <package-name> [-i https://pypi.example.com]
</syntaxhighlight>
By default, the command always looks for the latest version of the package and installs it. It also looks for dependencies listed in the [[Python_Language#Package_Metadata|package metadata]] and installs those dependencies as well.
<span id=dashr></span>A set of dependencies specified in a <code>[[#requirements.txt|requirements.txt]]</code> file can be installed with:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
pip install <package-name>
pip install -r requirements.txt
</syntaxhighlight>
</syntaxhighlight>
The command always looks for the latest version of the package and installs it. It also looks for dependencies listed in the [[Python_Language#Package_Metadata|package metadata]] and installs those dependencies as well.
 
===Installation Options===
====<tt>-i</tt>====
Specify the base URL of a custom Python Package Index. The default value if not specified is https://pypi.org/simple.


==Upgrade a Package==
==Upgrade a Package==
Use <code>install -U|--upgrade</code>.
<syntaxhighlight lang='bash'>
pip install --upgrade -r requirements.txt
</syntaxhighlight>
<syntaxhighlight lang='bash'>
pip install --upgrade -r requirements.txt
</syntaxhighlight>
==Freeze Dependencies==
==Freeze Dependencies==
The <code>freeze</code> command dumps all the packages and their versions to standard output, so you can redirect the output to a file that can be used to install the exact requirements into another system. Used to create <code>[[#requirements.txt|requirements.txt]]</code> files.  
The <code>freeze</code> command dumps all the packages and their versions to standard output, so you can redirect the output to a file that can be used to install the exact requirements into another system. Used to create <code>[[#requirements.txt|requirements.txt]]</code> files.  
<syntaxhighlight lang='bash'>  
<syntaxhighlight lang='bash'>  
pip freeze > requirements.txt
pip freeze > requirements.txt
</syntaxhighlight>
==Uninstall a Package==
It can be problematic if it is a dependency of other installed packages.
<syntaxhighlight lang='bash'>
pip uninstall somepackage
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 22:03, 9 November 2023

External

Internal

Overview

pip is the standard package manager for Python, that allows you install and manage package that are not part of the Python standard library. pip has been included with the Python installer since 3.4. pip looks for packages in PyPI

Installation

CentOS

https://linuxize.com/post/how-to-install-pip-on-centos-7/
yum install epel-release # On Amazon Linux, it works without this
yum install python-pip

Upgrade

python -m pip install --upgrade pip

requirements.txt File

requirements.txt

Version

pip --version

Operations

List Packages Installed in Environment

pip list

Display Details about a Package

pip show <package-name>

Searching Packages

The search command looks for packages published to PyPI.

pip search <query>

Install a Package

https://pip.pypa.io/en/stable/cli/pip_install/
pip install <package-name> [-i https://pypi.example.com]

By default, the command always looks for the latest version of the package and installs it. It also looks for dependencies listed in the package metadata and installs those dependencies as well.

A set of dependencies specified in a requirements.txt file can be installed with:

pip install -r requirements.txt

Installation Options

-i

Specify the base URL of a custom Python Package Index. The default value if not specified is https://pypi.org/simple.

Upgrade a Package

Use install -U|--upgrade.

pip install --upgrade -r requirements.txt
pip install --upgrade -r requirements.txt

Freeze Dependencies

The freeze command dumps all the packages and their versions to standard output, so you can redirect the output to a file that can be used to install the exact requirements into another system. Used to create requirements.txt files.

 
pip freeze > requirements.txt

Uninstall a Package

It can be problematic if it is a dependency of other installed packages.

 
pip uninstall somepackage