Last active
July 10, 2021 02:30
-
-
Save pulkitgoyal56/95a4343c83e039067f9874da04947c64 to your computer and use it in GitHub Desktop.
Check if Python interpreter is from a virtual environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def get_base_prefix_compat(): | |
"""Get base/real prefix, or sys.prefix if there is none.""" | |
return getattr(sys, "base_prefix", None) or getattr(sys, "real_prefix", None) or sys.prefix | |
def in_virtualenv(): | |
return get_base_prefix_compat() != sys.prefix | |
in_virtualenv() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment