PyCharm 2019.3 Help

Use requirements.txt

PyCharm makes it possible to track the unsatisfied dependencies in your projects, and provides integration with the major means of dependencies management.

Define requirements

  1. Create a new file in the root directory of your project.

  2. In the New File dialog, specify the filename. The recommended name for the requirements file is requirements.txt. When a file with this name is added to the root project directory, it is automatically detected by Python Integrated tools.

  3. Type the names of the required packages as plain text, for example:

    Django==2.0.3 Flask==0.12.2
    Note that recursive requirements syntax is supported: you can use the main requirements file, and include the other requirements with -r syntax.

You can also run pip freeze > requirements.txt in the command line to generate a requirements.txt file for your project. See for more details.

If the name of the requirements file differs from requirements.txt or when you have several requirements files in one project, you have to notify PyCharm about the requirements file you want to apply.

Configure the default requirements file

  1. Open the Settings/Preferences dialog Ctrl+Alt+S and select Tools | Python Integrated Tools.

  2. In the Package requirements file field, type the name of the requirements file or click the browse button and locate the desired file.

  3. Click OK to save the changes.

Though you can edit the dependencies management files according to their syntax, PyCharm provides quick fixes that enable populating these files.

Populate dependency management files

  1. Create or requirements.txt, as described in the sections Create and run and Defining requirements.

  2. In an import statement of a Python file, click a package which is not yet imported. PyCharm suggests a quick-fix:

    Apply a quick-fix
  3. Select and apply the suggested quick-fix. The package is added to the dependency management file.

PyCharm provides quick fixes and notifications related to the unsatisfied dependencies.

Install the required packages

  1. Open a project with the requirements file specified, a notification bar is displayed on top of any Python or requirements file opened in Editor:

    Notification on the requirements
  2. Click one of the provided links to satisfy or ignore requirements.

Last modified: 21 January 2020