How to connect R conda env to jupyter notebook

后端 未结 1 1908
长发绾君心
长发绾君心 2021-01-22 04:16

I am creating conda environment using following code

 conda create --prefix r_venv_conda r=3.3  r-essentials  r-base --y

Then I am activating t

相关标签:
1条回答
  • 2021-01-22 04:57

    Jupyter does not automatically recognize Conda environments, activated or not.

    Kernel Module

    First, for an environment to run as a kernel, it needs to have the appropriate kernel package installed. In this case, that is r-irkernel, so you need to run

    conda install -n r_venv_conda r-irkernel
    

    For Python kernels, it's ipykernel.

    Kernel Registration

    Second, kernels need to be registered with Jupyter. If you have Jupyter installed via Conda (say in an Anaconda base env), then I recommend using the nb_conda_kernels package, which enables auto-discovery of kernel-ready Conda-envs. This must be installed in the env that has jupyter installed (you only need one!), for example, if this is base, then

    conda install -n base nb_conda_kernels
    

    Please read the docs for details.

    If you are using a system-level installation of Jupyter (i.e., not installed by Conda), then you need to manually register your kernel.

    conda activate r_venv_conda
    Rscript -e 'IRkernel::installspec(name="ir33", displayname="R 3.3")'
    

    where you can set your own values for name and displayname. See IRkernel for details.

    Running Jupyter

    If using a Conda-installed Jupyter, again, it only needs to be installed in a single env. This is the env that should be activated before running jupyter notebook. Once running, then you select the kernel you wish to use.

    0 讨论(0)
提交回复
热议问题