Skip to content

Instantly share code, notes, and snippets.

@sleaze
Last active September 23, 2022 15:09
Show Gist options
  • Save sleaze/e0d0d4d5a8f4c686b7b9d30ff14ea7eb to your computer and use it in GitHub Desktop.
Save sleaze/e0d0d4d5a8f4c686b7b9d30ff14ea7eb to your computer and use it in GitHub Desktop.
Snippet for dynamically updating sys.path to include virtualenv when import fails
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