What makes in Python a virtual environment a virtual environment?

Viewed 159

I want to find the Python virtual environments ("venvs" for short) in my file system, and for this I need to know what set of files constitutes a venv.

Some tools - when they want to make sure a directory is a venv - check for the pyvenv.cfg file, but older virtual environments and environments created by Pipenv do not have this file. - Furthermore pyvenv.cfg does not seem to be necessary for activating the venv either.

So what is the minimal set of files to define a working virtual environment? And what is an easy way to check for this in Python?

Clarification:

With "working virtual environment" I mean:

  • A way to use a specific version of Python executable defined in that environment (and possibly different to the default system Python)
  • A way to use specific packages (usually installed via pip, bit that's not a requirement).
  • The Python executable in the venv should be aware of being run inside a venv (see sys.base_prefix and sys.prefix in the Python documentation.)
0 Answers
Related