0

Importing rpy2.robjects fails in the jupyter notebook with LookupError: 'show' not found, however, import works in the commandline python interpreter with activated environment. How can I make it work in the notebook?

I have created the conda environment with rpy2 and ipykernel installed and have linked it to jupyter via python -m ipykernel install --user --name env --display-name "env" (within the activated environment). I looked up the path of the environment in kernel.json under the path provided by jupyter kernelspec list and found it to be the correct one of my environment. I do not get the error when I start jupyter notebook from within the activated environment and try to import rpy2.rojects. I would have thought that this should not make any difference. Furthermore, when starting the python interpreter via ./python within the ~home/user/anaconda3/envs/env, I do obtain the error. It seems some environment variables are set differently when starting the notebook with or without activated environment, but I do not have any clue which and how. I'll be happy about any hints to understand the issue.

Marchhare
  • 29
  • 4

1 Answers1

0

It does make a difference whether an environment is activated. You've already pointed out one solution, start Jupyter in the activated environment, and the kernels will inherit the corresponding environment variables.

Anaconda also has a kernel provider that finds kernels in all conda environments and automatically activates the environment when the kernel starts.

Another way is that you write your own kernelspec that calls a script. In that script, you can activate the conda environment before starting the kernel.

Roland Weber
  • 3,395
  • 12
  • 26