How to know I'm using venv Python
- Solution 1: use
sys.prefix
that points to the Python directory - Solution 2 (the better way):
VIRTUAL_ENV
environment variable. When a virtual environment is activated, this is set to the venv’s directory, otherwise it’s None.
import os
print(os.environ.get('VIRTUAL_ENV'))
Was this page helpful?