Created
December 13, 2016 22:12
-
-
Save z-a-f/cc763e59f35b760061efce3adb60927e to your computer and use it in GitHub Desktop.
Running Jupyter Notebooks and IPython from Virtual Env
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
## Special thanks to http://stackoverflow.com/a/30650831/3606192 | |
## Place this file under '~/.ipython/profile_default/startup/' | |
import os | |
import sys | |
if 'VIRTUAL_ENV' in os.environ: | |
py_version = sys.version_info[:2] # formatted as X.Y | |
py_infix = os.path.join('lib', ('python%d.%d' % py_version)) | |
virtual_site = os.path.join(os.environ.get('VIRTUAL_ENV'), py_infix, 'site-packages') | |
dist_site = os.path.join('/usr', py_infix, 'dist-packages') | |
# OPTIONAL: exclude debian-based system distributions sites | |
sys.path = filter(lambda p: not p.startswith(dist_site), sys.path) | |
# add virtualenv site | |
sys.path.insert(0, virtual_site) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment