Conda installation environment and jupyter - different paths

320 views
Skip to first unread message

Mark Fuller

unread,
Mar 26, 2018, 1:20:17 PM3/26/18
to Cantera Users' Group
Hi all,
I'm getting a new machine setup (Fedora 27) and have elected to go the conda route instead of compiling Cantera.
After doing so and activating my environment (ChemEnv), I can load cantera in python at the command line, but when I open a jupyter notebook from my environment and then try to import cantera, I get "ImportError: No module named cantera"

The paths are clearly different:
From my terminal, where I can load cantera in python, I have sys.path as:
>>> sys.path
['', '/home/fuller/miniconda2/envs/ChemEnv/lib/python36.zip', '/home/fuller/miniconda2/envs/ChemEnv/lib/python3.6', '/home/fuller/miniconda2/envs/ChemEnv/lib/python3.6/lib-dynload', '/home/fuller/miniconda2/envs/ChemEnv/lib/python3.6/site-packages']

and in jupyter I get the non-environment / system path:
['',
 '/usr/lib/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/site-packages/IPython/extensions',
 '/home/fuller/.ipython']

I looked at https://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments , but I'm not entirely sure what I need to run for
"/path/to/kernel/env/bin/python -m ipykernel install --prefix=/path/to/jupyter/env --name
'python-my-env'" (I'm getting confused about which environment and path is which)
Is this even the right way to fix this problem or is there some other way to get cantera integrated into my jupyter notebooks without compiling cantera from source?

Thank you

Mark Fuller

unread,
Mar 26, 2018, 2:10:39 PM3/26/18
to Cantera Users' Group
So, I think I fixed it myself:
I installed ipykernel (python -m ipykernel install --user --name myenv --display-name "Python (myenv)") and nb_conda_kernels as at https://github.com/jupyter/jupyter/issues/245
I can now select a kernel from the kernel menu in jupyter (although I didn't look here before making changes) and I also now have two entries that seem to correspond to the conda environment - one as named using the above "--display-name" option and a default looking name indicating the Conda environment

Bryan W. Weber

unread,
Mar 26, 2018, 5:03:21 PM3/26/18
to Cantera Users' Group
Mark,

I've had success installing the ipykernel package into the environment (conda install ipykernel), which then creates a kernel available from the Jupyter Notebook package installed in the base environment. Did you install Jupyter Notebook in the base environment? From your Jupyter sys.path, it looks like the Notebook is installed for the system's Python.

Best,
Bryan
Reply all
Reply to author
Forward
0 new messages