I have been running the Jupyter notebooks with multiple conda environments (kernels). This was accomplished by installing nb_conda
and nb_conda_kernels
.
After installing both of the above packages and restarting the notebook server I seem to have access to both conda
environments in the jupyter
notebook. However, I could not confirm that the underlying shell has the correct environment. For example if I start a two notebook servers one with Python 2.7 and one with 3.6, I get expected answers for the python versions, but not for executed shell commands.
Python 2.7.13:
import sys
print(sys.version)
#succeed evidence for running py < 3
import commands
commands.getoutput('which python')
output:
2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
'/path/python/anaconda3/envs/py36/bin/python'
In this case I would have expected which python
to produce the version of python
that is active inside the Python 2.7.13 environment. But I know the path returned is actually the python
that is used in the Python 3.6 environment (see below)
Python 3.6:
import sys
print(sys.version)
import subprocess
subprocess.check_output(["which","python"])
output:
3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
b'/path/python/anaconda3/envs/py36/bin/python\n'
Also, in the Python 3.6 environment I had this failure, which makes sense because the commands
module was eliminated in Python 3:
# fail (evidence for running py 3.6 env)
import commands
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-9cbf0185e88f> in <module>()
1 # fail (evidence for running py 3.6 env)
----> 2 import commands
ModuleNotFoundError: No module named 'commands'
So, in either case the output of which python
gave the version of python from the environment in which I started the Jupyter notebook. This leads me to believe that while the Python environment is as expected, the shell environment is somehow inconsistent with the Python conda environment. Why is that true? Will it cause problems?