Skip to content Skip to sidebar Skip to footer

Activating A New Conda Env Through Shell From Within Jupyter Notebook

I'm working with a Jupyter Notebook written in Python 3, and I would like to run Python 2 scripts from within that Notebook. I was wondering if it's possible to run Shell commands

Solution 1:

As far as I know, you cannot activate another environment and have it work like that. What you can do is run that Python explicitly, something like

!/path/to/anaconda/envs/python2env/bin/python script_that_uses_python2.py

If I run

!/path/to/anaconda/envs/python2env/bin/python -c "import sys; print sys.path"

on my system, it only shows Python 2 directories, so it would probably find the correct imports. However, the variables from that script won't be available in your notebook. You could have the Python 2 file write out a Pickle file and try to read that, maybe...

Post a Comment for "Activating A New Conda Env Through Shell From Within Jupyter Notebook"