Last active
September 23, 2022 15:09
-
-
Save sleaze/e0d0d4d5a8f4c686b7b9d30ff14ea7eb to your computer and use it in GitHub Desktop.
Snippet for dynamically updating sys.path to include virtualenv when import fails
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
import os | |
import sys | |
try: | |
import sqlite3 | |
import yaml | |
except ImportError: | |
# n.b. Dynamically activate virtualenv if needed. | |
sys.path.append(os.path.realpath('%s/venv/lib/python3.6/site-packages' % os.path.dirname(__file__))) | |
import sqlite3 | |
import yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment