Skip to content

Pip and requirements.txt

pip is the official tool for installing and managing packages in Python. Together with the requirements.txt file, it allows you to easily control your project dependencies and share them with others.


  • pip is the package manager for Python.
  • It allows you to easily install, update, and uninstall libraries from the terminal.
Ventana de terminal
pip install package_name

  • It is a text file where all the dependencies (packages and versions) necessary for your project are listed.
  • It facilitates the installation of all the libraries at once, ideal for sharing projects or working in a team.
requests==2.31.0
numpy>=1.25.0
flask

With your virtual environment activated and all packages installed, run:

Ventana de terminal
pip freeze > requirements.txt

This will generate a file with all current dependencies.


How to install dependencies from requirements.txt?

Section titled “How to install dependencies from requirements.txt?”

To install all the dependencies listed in the file:

Ventana de terminal
pip install -r requirements.txt

  • Use a virtual environment for each project.
  • Update the requirements.txt file each time you add or remove packages.
  • Include requirements.txt in your repository to facilitate collaboration.

  • pip allows you to install and manage packages easily.
  • requirements.txt helps to share and reproduce your project environment.
  • They are essential tools for any modern Python developer.

Ready to manage your dependencies like a pro? Try creating and using a requirements.txt file in your next project!