Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Project Requirements | Virtual Environment
Mastering Python: Annotations, Errors and Environment
course content

Contenido del Curso

Mastering Python: Annotations, Errors and Environment

Mastering Python: Annotations, Errors and Environment

1. Annotations
2. Function Arguments in Details
3. Error Handling
4. Virtual Environment

bookProject Requirements

There are many different modules that are suitable for various projects. They are installed using the pip command (for example, pip install pandas). And each project has its own list of such modules, which is usually stored in a file called requirements.txt. Here's an example of such a file for one of Django projects:

Here's a possible translation:

You can see that the list is arranged by lines: one line corresponds to one module. The module version can also be specified using ==.

Note

If versions are not specified (there are no == signs and no version numbers), the latest version of these modules will be installed. This is dangerous because different versions may be incompatible or may have different functionality.

There are also other version specification, such as:

  • ==: Exact version match.
  • ~=: Compatible version.
  • >=: Minimum version.
  • <=: Maximum version.
  • >: Minimum compatible version.
  • <: Maximum compatible version.
  • !=: Non-equal version.

The regular specification is ==, and other notations are not very useful because in real-world development, precise module versions should be present. This allows for seamless migration of the project between devices (across developers in a company) without bugs and errors.

How to install requirements?

To install the requirements for a Python project, you can use the following steps:

  1. Activate the virtual environment where you want to install the requirements.
  2. Run this command:

Note

Ensure that requirements.txt is placed in the Project Folder with Virtual Environment (venv).

How to create requirements?

If you write the requirements.txt file yourself, you may lose or forget something. Python offers a great solution for automatically creating the requirements file.

To create the requirements file, you can write just one command in the terminal:

The Python interpreter will collect all dependent modules and their versions, and then automatically populate the requirements.txt file.

Note

The requirements file is usually named requirements.txt. You can use another name, but developers are accustomed to a simple and common name, so it's better to use requirements.txt and not invent other names.

1. What command is used to install requirements?
2. What command is used to create requirements file?
What command is used to install requirements?

What command is used to install requirements?

Selecciona unas respuestas correctas

What command is used to create requirements file?

What command is used to create requirements file?

Selecciona unas respuestas correctas

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 3
some-alt