Get The Most Affordable Hosting in the World!
Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.
Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!
Get Started Now!Python's standard library is a large collection of ready-to-use modules and packages. In addition to these packages, a Python programmer often needs to use certain third-party libraries. Third-party Python packages are hosted on a repository called Python Package Index (https://pypi.org/).
To install a package from this repository, you need a package manager tool. PIP is one of the most popular package managers.
The PIP utility is automatically installed with Python's standard distribution especially with version 3.4 onwards. It is present in the scripts folder inside Python's installation directory. For example, when Python 3.11 is installed on a Windows computer, you can find pip3.exe in C:\Python311\Scripts folder.
If pip is not installed by default, it can be installed by the following procedure.
Download get-pip.py script from following URL −
To install run above script from command prompt −
In scripts folder both pip and pip3 are present. If pip is used to install a certain package, its Python 2.x compatible version will be installed. Hence to install Python 3 compatible version, use pip3.
Install a Package
To install a certain package from PyPi, use install command with PIP. Following command installs Flask library in the current Python installation.
The package, along with its dependencies if any, will be installed from the PyPI repository. The above command produces following log in the terminal −
By default, the latest available version of the desired package is installed. To specify the version required,
To test if the package installation is complete, open Python interpreter and try to import it and check the version. If the package hasn't been successfully installed, you get a ModuleNotFoundError.
PIP utility works with −
-
PyPI (and other indexes) using requirement specifiers.
-
VCS project urls.
-
Local project directories.
-
Local or remote source archives.
Use requirements.txt
You can perform package installation at once by mentioning the list of required packages in a text file named as requirements.txt.
For example, the following requirements.txt file contains list of dependencies to be installed for FastAPI library.
anyio==3.6.2 click==8.1.3 colorama==0.4.6 fastapi==0.88.0 gunicorn==20.1.0 h11==0.14.0 idna==3.4 pydantic==1.10.4 sniffio==1.3.0 starlette==0.22.0 typing_extensions==4.4.0 uvicorn==0.20.0
Now use the -r switch in PIP install command.
pip3 install -r requirements.txt
The PIP utility is used with along with following commands −
pip uninstall
This command is used to uninstall one or more packages already installed.
Syntax
This will uninstall the packages along with the dependencies.
Example
pip3 uninstall flask
You will be asked confirmation for removal before proceeding.
pip list
This command gives a list installed packages, including editables. Packages are listed in a case-insensitive sorted order.
Syntax
Following switches are available with pip list command −
-o, --outdated: List outdated packages
-u, --uptodate : List uptodate packages
pip show
This command shows information about one or more installed packages. The output is in RFC-compliant mail header format.
Syntax
Example
pip freeze
This command outputs installed packages in requirements format. All the packages are listed in a case-insensitive sorted order.
Syntax
The output of this command can be redirected to a text file with the following command −
pip3 freeze > requirements.txt
pip download
This command downloads packages from −
-
PyPI (and other indexes) using requirement specifiers.
-
VCS project urls.
-
Local project directories.
-
Local or remote source archives.
In fact, pip download does the same resolution and downloading as pip install, but instead of installing the dependencies, it collects the downloaded distributions into the directory provided (defaulting to the current directory). This directory can later be passed as the value to pip install --find-links to facilitate offline or locked down package installation.
Syntax
pip search
This command searches for PyPI packages whose name or summary contains the given query.
Syntax
pip config
This command is used to manage local and global configuration.
Subcommands
-
list − List the active configuration (or from the file specified).
-
edit − Edit the configuration file in an editor.
-
get − Get the value associated with command.option.
-
set − Set the command.option=value.
-
unset − Unset the value associated with command.option.
-
debug − List the configuration files and values defined under them.
Configuration keys should be dot separated command and option name, with the special prefix "global" affecting any command.
Example
This would configure the index url for all commands.
This would configure a 10 second timeout only for "pip download" commands.
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.