Skip to content

Instantly share code, notes, and snippets.

Last active November 18, 2022 23:26
What would you like to do?
#!/usr/bin/env python3
def venv_exec():
import os, sys
from pathlib import Path
basedir = Path(__file__).parent.resolve()
executable = Path(sys.executable)
try: executable.relative_to(basedir)
except ValueError as e:
p = next(basedir.glob('*/bin/python3'))
os.environ['VIRTAUL_ENV'] = str(p.parent.parent)
if 'PYTHON_HOME' in os.environ: del os.environ['PYTHON_HOME']
cmd = str(Path(basedir, p))
args = list(sys.argv)
args.insert(0, cmd)
os.execvp(cmd, args)
raise e
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment