/

Installing 3rd Party Packages in Python using `pip`

Installing 3rd Party Packages in Python using pip

Python is a comprehensive programming language with a vast collection of utilities in its standard library. However, sometimes we need additional functionality that is not built-in. This is where 3rd party packages come into play.

Packages are created and made available as open-source software by individuals and companies for the Python community. These packages are hosted on the Python Package Index (PyPI) at https://pypi.org, and can be easily installed using pip, the package installer for Python.

Currently, there are over 270,000 packages freely available on PyPI.

Prerequisites

Before proceeding, make sure you have pip installed. Typically, pip comes pre-installed when you install Python. If not, please refer to the Python installation instructions to install pip before continuing.

Installing Packages

To install a package, simply use the pip install command followed by the package name:

1
pip install <package>

In case you run into any issues, you can also use the python -m command:

1
python -m pip install <package>

For example, let’s install the popular requests package, which is widely used for making HTTP requests:

1
pip install requests

Once installed, the package will be available for use in all your Python scripts. Packages are installed globally, but the exact location may vary depending on your operating system.

Upgrading and Downgrading Packages

To upgrade a package to its latest version, use the following command:

1
pip install -U <package>

If you need to install a specific version of a package, you can specify the version number using the following command:

1
pip install <package>==<version>

Uninstalling Packages

To uninstall a package that you no longer need, use the pip uninstall command followed by the package name:

1
pip uninstall <package>

Viewing Package Information

To view detailed information about an installed package, including the version, documentation website, and author information, use the pip show command followed by the package name:

1
pip show <package>

That’s it! Now you know how to easily install, upgrade, downgrade, and uninstall 3rd party packages in Python using pip.

tags: [“Python”, “pip”, “package installation”, “package management”]