What is the differene between "Python 3.9" and "Python 3.9 (venv)" interpreters?

Viewed 1933

If I start a new python project, pycharm sets the Python 3.9 (venv) as default interpreter. With this, I need always reinstall packages, that were already installed, so I changed to Python 3.9 interpreter, but I don't know what is the real difference, and wich one should I use.

Python 3.9 and Python 3.9(venv) option

1 Answers

The difference is that, unlike the base interpreter, which is not context dependent, the venv (virtualenv) interpreter serves a specific project.

The advantage of using a virtual environment is that you can maintain different packages and package versions depending on the requirements and dependencies of each project separately.

In order to avoid reinstalling the same packages each time you can:

  1. Inherit global packages. By default the venv interpreter comes with the minimal packages installed, but it is possible to inherit the global packages. I see you are using PyCharm, so you can follow these instructions under "If New environment is selected:", section 3.

    You can also achieve this using the virtualenv package directly by adding "--system-site-packages" to the creation command (e.g. virtualenv venv --system-site-packages).

  2. Create a requirements.txt file. Pip can install packages using a file the specifies the packages (and optionally package versions) you would like to install. You can run:
    pip install -r /path/to/requirements.txt Where the file is usually located at the root folder of the project.

    In order to create such a file from an existing interpreter you can use the command

    pip freeze > /path/to/requirements.txt

I personally prefer the second option.

Related