All the major Linux distributions has their own package manager that helps users to install, update, remove packages and update their system to next available version (I mean, operating system upgrade can be taken care in the same way as well).
When it comes to python based applications, you wont get a latest version of packages from distribution official repository since those were already included in the repository at the time of operating system build.
Dev team wont rebuild all the packages whenever new release come until its necessary to fix some important bug. So, I would advise to install pip on your system to get a latest version of python build packages from python repository.
We have already covered in our previous article about other package managers such as Yum, Dnf, Apt-Get, Apt, Rpm, Dpkg, and Snop.
Suggested Read :
(#) YUM Command To Manage Packages on RHEL/CentOS Systems
(#) DNF (Fork of YUM) Command To Manage Packages on Fedora System
(#) Zypper Command To Manage Packages On openSUSE & suse Systems
(#) Apt-Get & Apt-Cache commands to manage packages on Debian Based Systems
(#) Pacman Command To Manage Packages On Arch Linux Based Systems
(#) APT (Advanced Packaging Tool) : Advanced Package Management tool for Debian Based Systems
(#) Snap Brand New Package Manager for Ubuntu
(#) URPMI Package Management tool for Mageia System
(#) Dpkg Command To Manage Packages On Debian Based Systems
(#) RPM commands to manage packages on RHEL based systems
What is Python
Python is a widely used high-level programming language for general-purpose programming that lets you work quickly and integrate systems more effectively.
What is pip
pip is a modern python module bundled with setup tools, it’s one of the recommended tool for installing Python packages in Linux.
What is PyPi
The Python Package Index (PyPi) is a repository of software for the Python programming language and currently 117803 packages are available.
How to install pip
Run the following commands based on your distribution to install pip on Linux.
For Debian/Ubuntu
, use apt-get command or apt command to install pip.
[For Python2] $ sudo apt install python-pip python-setuptools [For Python3] $ sudo apt install python3-pip
pip doesn’t shipped with RHEL/CentOS
system official repository so, enable EPEL Repository and use YUM command to install pip.
$ sudo yum install python-pip python-devel python-setuptools
For Fedora
system, use dnf Command to install pip.
[For Python2] $ sudo dnf install python-pip [For Python3] $ sudo dnf install python3
For Arch Linux
based systems, use Pacman Command to install pip.
[For Python2] $ sudo pacman -S python2-pip python-setuptools [For Python3] $ sudo pacman -S python-pip python3-setuptools
For openSUSE
system, use Zypper Command to install pip.
[For Python2] $ sudo pacman -S python-pip [For Python3] $ sudo pacman -S python3-pip
Run the following command to upgrade pip to latest available version
$ sudo pip install -U pip
How to use pip
pip tool comes with easy to use syntax like how other Linux distribution package mangers has. It help users to install, remove, search, and update python packages smoothly from python repository.
pip [command] [options] [Pacakge Name]
How to install Package
Install package and its dependencies from PyPI.
pip [install] [options] [Pacakge Name]
1) Install latest version of python package.
$ sudo pip install netutils-linux Collecting netutils-linux Collecting argparse (from netutils-linux) Using cached argparse-1.4.0-py2.py3-none-any.whl Collecting colorama (from netutils-linux) Using cached colorama-0.3.9-py2.py3-none-any.whl Collecting prettytable (from netutils-linux) Collecting ipaddress (from netutils-linux) Using cached ipaddress-1.0.18-py2-none-any.whl Collecting six (from netutils-linux) Using cached six-1.11.0-py2.py3-none-any.whl Collecting pyyaml (from netutils-linux) Installing collected packages: argparse, colorama, prettytable, ipaddress, six, pyyaml, netutils-linux Successfully installed argparse-1.4.0 colorama-0.3.9 ipaddress-1.0.18 netutils-linux-2.5.0 prettytable-0.7.2 pyyaml-3.12 six-1.11.0
2) Install specific version of python package.
$ sudo pip install netutils-linux==1.0.4
3) Install Minimum version of python package.
$ sudo pip install 'netutils-linux>=1.0.4'
4) Install Development version of python package. By default, pip only finds stable versions.
$ sudo pip install --pre netutils-linux
How to upgrade a Package
Upgrade specified packages to the newest available version.
$ sudo pip install --upgrade netutils-linux Collecting netutils-linux Downloading netutils-linux-2.5.0.tar.gz Collecting argparse (from netutils-linux) Downloading argparse-1.4.0-py2.py3-none-any.whl Collecting colorama (from netutils-linux) Downloading colorama-0.3.9-py2.py3-none-any.whl Collecting ipaddress (from netutils-linux) Downloading ipaddress-1.0.18-py2-none-any.whl Collecting prettytable (from netutils-linux) Downloading prettytable-0.7.2.zip Collecting pyyaml (from netutils-linux) Downloading PyYAML-3.12.tar.gz (253kB) 100% |████████████████████████████████| 256kB 734kB/s Collecting six (from netutils-linux) Downloading six-1.11.0-py2.py3-none-any.whl Building wheels for collected packages: netutils-linux, prettytable, pyyaml Running setup.py bdist_wheel for netutils-linux ... done Stored in directory: /home/magi/.cache/pip/wheels/d9/bd/18/7d5e9f30030c84d15025b30f83b01161ac52beb6992596bb48 Running setup.py bdist_wheel for prettytable ... done Stored in directory: /home/magi/.cache/pip/wheels/b6/90/7b/1c22b89217d0eba6d5f406e562365ebee804f0d4595b2bdbcd Running setup.py bdist_wheel for pyyaml ... done Stored in directory: /home/magi/.cache/pip/wheels/2c/f7/79/13f3a12cd723892437c0cfbde1230ab4d82947ff7b3839a4fc Successfully built netutils-linux prettytable pyyaml Installing collected packages: argparse, colorama, ipaddress, prettytable, pyyaml, six, netutils-linux Successfully installed argparse-1.4.0 colorama-0.3.9 ipaddress-1.0.18 netutils-linux-2.5.0 prettytable-0.7.2 pyyaml-3.12 six-1.11.0
How to download a Package
Download a package and all of its dependencies into directory instead of install.
$ sudo pip download netutils-linux Collecting netutils-linux Using cached netutils-linux-2.5.0.tar.gz Saved ./netutils-linux-2.5.0.tar.gz Collecting argparse (from netutils-linux) Using cached argparse-1.4.0-py2.py3-none-any.whl Saved ./argparse-1.4.0-py2.py3-none-any.whl Collecting colorama (from netutils-linux) Using cached colorama-0.3.9-py2.py3-none-any.whl Saved ./colorama-0.3.9-py2.py3-none-any.whl Collecting ipaddress (from netutils-linux) Using cached ipaddress-1.0.18-py2-none-any.whl Saved ./ipaddress-1.0.18-py2-none-any.whl Collecting prettytable (from netutils-linux) Using cached prettytable-0.7.2.zip Saved ./prettytable-0.7.2.zip Collecting pyyaml (from netutils-linux) Using cached PyYAML-3.12.tar.gz Saved ./PyYAML-3.12.tar.gz Collecting six (from netutils-linux) Using cached six-1.11.0-py2.py3-none-any.whl Saved ./six-1.11.0-py2.py3-none-any.whl Successfully downloaded netutils-linux argparse colorama ipaddress prettytable pyyaml six
How to Uninstall a Package
pip is able to uninstall most installed packages.
$ sudo pip uninstall netutils-linux Uninstalling netutils-linux-2.5.0: /home/magi/.local/bin/autorps /home/magi/.local/bin/autotune-reductor /home/magi/.local/bin/autoxps /home/magi/.local/bin/detect_virt.py /home/magi/.local/bin/detect_virt.pyc /home/magi/.local/bin/irqtop /home/magi/.local/bin/link-rate /home/magi/.local/bin/maskify /home/magi/.local/bin/maximize-cpu-freq /home/magi/.local/bin/network-top . . /home/magi/.local/lib/python2.7/site-packages/netutils_linux_tuning/test_rss_ladder.pyc /home/magi/.local/lib/python2.7/site-packages/netutils_linux_tuning/test_rx_buffers.py /home/magi/.local/lib/python2.7/site-packages/netutils_linux_tuning/test_rx_buffers.pyc Proceed (y/n)? y Successfully uninstalled netutils-linux-2.5.0
How to list installed packages
List installed packages, including editables.
1) List installed packages.
$ pip list adium-theme-ubuntu (0.3.4) beautifulsoup4 (4.5.3) certifi (2017.7.27.1) chardet (3.0.4) colorama (0.3.9) configobj (5.0.6) cryptography (1.7.1) enum34 (1.1.6) green-recorder (3.0.4) html5lib (0.999999999) idna (2.6) ipaddress (1.0.18) keyring (10.3.1) keyrings.alt (2.2) lxml (3.7.3) . .
2) List outdated packages (excluding editables), and the latest version available.
$ pip list --outdated beautifulsoup4 (4.5.3) - Latest: 4.6.0 [wheel] certifi (2017.7.27.1) - Latest: 2017.7.27.1 [wheel] chardet (3.0.4) - Latest: 3.0.4 [wheel] colorama (0.3.9) - Latest: 0.3.9 [wheel] configobj (5.0.6) - Latest: 5.0.6 [sdist] cryptography (1.7.1) - Latest: 2.0.3 [wheel] enum34 (1.1.6) - Latest: 1.1.6 [wheel] html5lib (0.999999999) - Latest: 0.999999999 [wheel] idna (2.6) - Latest: 2.6 [wheel] ipaddress (1.0.18) - Latest: 1.0.18 [wheel] keyring (10.3.1) - Latest: 10.4.0 [wheel] keyrings.alt (2.2) - Latest: 2.3 [wheel] lxml (3.7.3) - Latest: 4.0.0 [wheel] ndg-httpsclient (0.4.2) - Latest: 0.4.3 [wheel] netutils-linux (2.5.0) - Latest: 2.5.0 [sdist] numpy (1.12.1) - Latest: 1.13.1 [wheel] Pillow (4.0.0) - Latest: 4.2.1 [wheel] pip (9.0.1) - Latest: 9.0.1 [wheel] . .
2) List installed packages with column formatting.
$ pip list --format columns Package Version ------------------ -------------------------------------------------------- adium-theme-ubuntu 0.3.4 beautifulsoup4 4.5.3 certifi 2017.7.27.1 chardet 3.0.4 colorama 0.3.9 configobj 5.0.6 cryptography 1.7.1 enum34 1.1.6 green-recorder 3.0.4 html5lib 0.999999999 idna 2.6 ipaddress 1.0.18 keyring 10.3.1 keyrings.alt 2.2 lxml 3.7.3 ndg-httpsclient 0.4.2 netutils-linux 2.5.0 numpy 1.12.1 Pillow 4.0.0 pip 9.0.1 powerline-status 2.6.dev9999+git.9bebc2fe7f0f6a73412c515711d94c2177e31553 prettytable 0.7.2 . .
Print installed packages info
Show information about one or more installed packages.
1) Show information about a package.
$ pip show netutils-linux Name: netutils-linux Version: 2.5.0 Summary: Bunch of utils to simplify linux network troubleshooting and performance tuning. Home-page: https://github.com/strizhechenko/netutils-linux Author: Oleg Strizhechenko Author-email: [email protected] License: MIT Location: /home/magi/.local/lib/python2.7/site-packages Requires: argparse, colorama, prettytable, ipaddress, six, pyyaml
2) Show all information (detailed information) about a package.
$ pip show --verbose netutils-linux Name: netutils-linux Version: 2.5.0 Summary: Bunch of utils to simplify linux network troubleshooting and performance tuning. Home-page: https://github.com/strizhechenko/netutils-linux Author: Oleg Strizhechenko Author-email: [email protected] License: MIT Location: /home/magi/.local/lib/python2.7/site-packages Requires: argparse, colorama, prettytable, ipaddress, six, pyyaml Metadata-Version: 2.0 Installer: pip Classifiers: Development Status :: 3 - Alpha Intended Audience :: Developers Operating System :: MacOS Operating System :: POSIX Programming Language :: Python Programming Language :: Python :: 2.6 Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.4 Programming Language :: Python :: 3.6 Topic :: Software Development Topic :: Utilities Entry-points:
Search a package
Search a packages from PyPI.
$ pip search netutils-linux linux-system-administration (0.0.1) - Installation and Update-Files for Ubuntu alignak_checks_linux_nrpe (0.4.2) - Alignak checks pack for Linux NRPE monitored hosts fetch-linux-security-patches-and-kernel (0.0.1.dev10) - Download the latest linux-hardened or unofficial grsecurity 4.9 patch and the matching linux kernel version. appdynamics-proxysupport-linux-x64 (1.8.0.51.1) - Proxysupport for AppDynamics Python agent appdynamics-proxysupport-linux-x86 (1.8.0.51.1) - Proxysupport for AppDynamics Python agent appdynamics-bindeps-linux-x86 (7.0) - Dependencies for AppDynamics Python agent appdynamics-bindeps-linux-x64 (7.0) - Dependencies for AppDynamics Python agent HTSeq-arm-linux (0.6.1) - HTSeq for ARM (armv7l) Linux GNUroot Debian on NVIDIA Shield Tablet [Tegra K1] pysam-arm-linux (0.8.3) - pysam for ARM (armv7l) Linux GNUroot Debian on Nvidia Shield Tablet [Tegra K1] box-linux-sync (0.1.0) - Linux client for Box.com detect_linux_distro (1.3) - Detect Linux distribution dots-linux (0.0.1) - Linux System Manager. EpistaSim_Linux (1.1.0) - Epistasis simulator of SNP patterns in Linux ITI1480A-linux (3.0) - Tools for the ITI1480A usb protocol analyser netshow-linux-lib (1.1.5) - Netshow Provider for Linux Operating Systems straw-linux (0.0.1) - A simple OS monitoring for linux TransFabric-Python2X-Linux-x64 (1.0) - linux (0.0) - Linux-Screen-Reader (0.2.1) - Linux Screen Reader: Extensible assistive technology linux-nethelp (1.0.1) - linux network helpers - e.g. list interfaces and their IP addresses tourbillon-linux (0.4.1) - A tourbillon plugin for collecting metrics from linux. linux-metrics (0.1.4) - linux-metrics - System Metrics/Stats Library for Linux linux-utils (0.5) - Linux system administration tools for Python netutils-linux (2.5.0) - Bunch of utils to simplify linux network troubleshooting and performance tuning. INSTALLED: 2.5.0 (latest) mccdaq_linux (1.4.8) - Python drivers for Measurement Computing devices (mccdaq.com) on linux vapour_linux_amd64 (0.2.1) - This package contains binary executable dependencies for the master.
freeze command usage
Output installed packages in requirements format which help us to install all the packages into another environment like Python2 to Python3 environment when you want to move all the installed packages.
$ sudo pip freeze $ sudo env1/bin/pip freeze > requirements.txt $ sudo env2/bin/pip install -r requirements.txt
If you want to know more option which is available for pip, simply navigate to man page.
$ pip help
Reference Link : pip usage