Skip to content

Instantly share code, notes, and snippets.

@thoroc
Created February 2, 2022 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoroc/0acbca172cef5650b3d7083e9dae33a7 to your computer and use it in GitHub Desktop.
Save thoroc/0acbca172cef5650b3d7083e9dae33a7 to your computer and use it in GitHub Desktop.
Checking if we are in a virutalenv for python
#! /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