Skip to content

Instantly share code, notes, and snippets.

@emmanuellyautomated
Last active November 10, 2017 22:30
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 emmanuellyautomated/5801f924423ac09f591fa3c33a9cfa74 to your computer and use it in GitHub Desktop.
Save emmanuellyautomated/5801f924423ac09f591fa3c33a9cfa74 to your computer and use it in GitHub Desktop.
If a virtualenv is activated, this will return the full path of the dependency named.
import os
import sys
def find_venv_dependency(name):
if not hasattr(sys, 'real_prefix'):
return # venv not activated
venv = sys.prefix.split('/')[len(os.getcwd().split('/'))]
for root, dirs, files in os.walk(venv):
if name in dirs:
return f'{root}/{name}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment