PyCharm 2018.3 Help

Configuring Pipenv Environment

Pipenv is a tool that provides all necessary means to create a virtual environment for your Python project. It automatically manages project packages through the Pipfile file as you install or uninstall packages.

Pipenv also generates the Pipfile.lock file, which is used to produce deterministic builds and create a snapshot of your working environment. This might be particularly helpful for security sensitive deployment, when project requirements and packages versions are critical. For more details about pipenv, see project documentation at docs.pipenv.org.

To use Pipenv with PyCharm, you need to implement several preparation steps.

Install Pipenv

  1. Run the following command to ensure you have pip installed in your system:

    $ pip --version

    You should expect to receive a system response indicating the pip version. If no pip is discovered, install it as described in the Installation Instructions. Alternatively, you can download and install Python from http://python.org.

  2. Install pipenv by running the following command:

    $ pip install --user pipenv

    When installation completes, you will see the following message:

    System response on successful pipenv installation
  3. For your convenience, you might add the user base’s binary directory to your PATH environmental variable. If you skip this procedure, PyCharm will prompt you to specify the path to the pipenv executable when adding a pipenv environment.

    1. Run the following command:

      $ py -m site --user-site

      A sample output can be:

      C:\Users\jetbrains\AppData\Roaming\Python\Python37\site-packages
    2. Replace site-packages with Scripts in this path to receive a string for adding to the PATH variable, for example:

      $ setx PATH "%PATH%;C:\Users\jetbrains\AppData\Roaming\Python\Python37\Scripts"
    1. Run the following command to find the user base's binary directory:

      $ python -m site --user-base

      A sample output can be

      /Users/jetbrains/.local
    2. Add bin to this path to receive a string for adding to the ~/.bashrc file, for example:

      $ export PATH="$PATH:Users/jetbrains/.local/bin"
    3. Run the following command to make the changes effective:

      $ source ~./bashrc
    4. Ensure you have enabled bashrc in your bash_profile.

At any time you can alter the specified path to the pipenv executable in the project settings. In the Settings/Preferences dialog (Ctrl+Alt+S), navigate to Tools | Python Integrated Tools, and type the target path in the Path ot Pipenv executable field.

After the preparation steps are done, you can use pipenv to create a virtual environment for new or existing projects.

Set pipenv for a new Python project

  1. Initiate creating a new Python project as described in Creating a pure Python project.

  2. In the New Project dialog, click Expand to expand the Project Interpreter node, select New environment using, and from the list of available virtual environments select Pipenv.

    Select Pipenv when creating a new Python project
  3. If you have added the user base’s binary directory to your PATH environmental variable, you don't need to set any additional options: the path to the pipenv executable will be autodetected:

    Path to the pipenve executable is autodetected
  4. Click OK to complete the task.

  5. If you have not modified the PATH variable, PyCharm shows an error message: Pipenv executable is not found. Discover the proper executable path as described in the pipenv installation procedure and enter the target string in the Pipenv executable field, for example: C:\Users\jetbrains\AppData\Roaming\Python\Python37\Scripts\pipenv.exe (Windows) or /Users/jetbrains/.local/bin/pipenv (macOS).

    Click OK to save the changes and complete the task.

You can also set up pipenv for any of your earlier created projects.

Configure pipenv for an existing Python project

  1. In the Settings/Preferences dialog (Ctrl+Alt+S) expand the Project <project name> node, and click Project Interpreter.

  2. Click project interpreter and choose Add .... The Add Python Interpreter dialog box opens.

  3. In the left-hand pane of this dialog, click Pipenv Environment.

    Adding a Pipenv environment
  4. If you have added the user base’s binary directory to your PATH environmental variable, you don't need to set any additional options: the path to the pipenv executable will be autodetected.

    If you see the Pipenv executable is not found error message, follow the pipenv installation procedure to discover the executable path and add it to the Pipenv executable field.

  5. Click OK to complete the task.

Once all the steps are done, the new pipenv environment is set for your project and the packages listed in the Pipfile are installed.

If you open a project with a Pipfile file added but no any interpreter configured, PyCharm offers you to use Pipenv environment.

Pipenv inspection

If you select this option, PyCharm sets pipenv for you automatically. Alternatively, you can click Configure Python interpreter to follow the standard workflow.

Similarly, when you open a project with a Pipfile file in PyCharm for the very first time, for example, by checking it out from the Version Control, the Pipenv virtual environment will be configured automatically.

When you have set the Pipenv virtual environment as a project interpreter, all available packages are added from the source defined in PipfilePipfile. The packages are installed, removed, and updated in the list of the packages through pipenv rather than through pip.

Last modified: 27 February 2019

See Also