Created
October 2, 2024 02:11
-
-
Save pwalkr/e20335f174fed0e03f4e50b34a44e74b to your computer and use it in GitHub Desktop.
Self-virtualizing python script
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 os | |
import subprocess | |
import sys | |
if 'VIRTUAL_ENV' not in os.environ: | |
os.environ['VIRTUAL_ENV'] = os.path.realpath('.venv') # Replace .venv with the virtual environment to load | |
virtual_python = os.environ['VIRTUAL_ENV'] + '/bin/python' | |
subprocess.call([virtual_python] + sys.argv) | |
sys.exit() | |
# import only_available_in_venv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment