Created
February 2, 2022 09:14
-
-
Save thoroc/0acbca172cef5650b3d7083e9dae33a7 to your computer and use it in GitHub Desktop.
Checking if we are in a virutalenv for python
This file contains 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
#! /usr/local/bin/python3 | |
import sys | |
def is_venv(): | |
return (hasattr(sys, 'real_prefix') or | |
hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) | |
if __name__ == "__main__": | |
if is_venv(): | |
print("You are running in a virtual env") | |
else: | |
print(""" | |
Please create & activate a virtual env: | |
virtualenv .venv && source .venv/bin/activate | |
""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment