How to determine if Python is running inside a virtualenv?
The reliable and documented way is to compare sys.prefix and sys.base_prefix. If they’re equal, you’re not in a virtual environment, otherwise you are. Inside a venv, sys.prefix points to the directory of the virtual environment, and sys.base_prefix to the Python interpreter used to create the environment. This is documented under How venvs work: It is … Read more