PIP is the official package manager for Python. It lets you install, upgrade, list, and uninstall third-party libraries that are not included in the standard Python library. With PIP, you can quickly add powerful tools like requests, numpy, and many more to your projects.
requirements.txt is a file that stores all your project dependencies.The general syntax of a PIP command is:
# General pip command syntax
pip <command> [options] [package_name]
install – install a new package.list – show all installed packages.uninstall – remove a package.freeze – output installed packages in a format suitable for requirements.txt.--upgrade – upgrade an existing package to the latest version.
# Install requests library
pip install requests
# List all installed packages
pip list
# Upgrade requests library
pip install --upgrade requests
# Uninstall requests library
pip uninstall requests
# Save installed packages to requirements.txt
pip freeze > requirements.txt
# Install packages from requirements.txt
pip install -r requirements.txt
pip install requests Downloads the requests package from PyPI and installs it so you can use import requests in your Python code.pip list Shows all installed packages and their versions. Useful to quickly check what is available in your environment.pip install --upgrade requests Updates the requests package to the latest version that matches your constraints.pip uninstall requests Removes the package from your environment after asking for confirmation.pip freeze > requirements.txt Saves all installed packages and their exact versions into a requirements.txt file.pip install -r requirements.txt Reads the file and installs all listed packages, recreating the same environment on another machine.pip --version to check if PIP is installed and which version you have.pip install --upgrade pip to keep PIP itself up to date.requirements.txt (for example, requests==2.32.0) to ensure stability.requirements.txt file to version control so others can recreate your environment easily.numpy package using PIP and verify it appears in pip list.pandas) using pip install --upgrade pandas.requirements.txt file for your current project with pip freeze > requirements.txt, then recreate the environment in a new virtual environment using pip install -r requirements.txt.