how can I find out which python virtual environment I am using?

Kay picture Kay · Dec 28, 2018 · Viewed 13.8k times · Source

I have several virtual environment in my computer and sometimes I am in doubt about which python virtual environment I am using. Is there an easy way to find out which virtual environment I am connected to?

Answer

wpercy picture wpercy · Dec 28, 2018

You can use sys.prefix to determine which virtualenv you're in.

import sys
print(sys.prefix)

from the sys docs

A string giving the site-specific directory prefix where the platform independent Python files are installed