How to add conda environment to jupyter lab
A solution using nb_conda_kernels
. First, install it in your base environment :
(base)$ conda install -c conda-forge nb_conda_kernels
Then in order to get a kernel for the conda_env cenv
:
$ conda activate cenv
(cenv)$ conda install ipykernel
(cenv)$ conda deactivate
You will get a new kernel named Python [conda env:cenv]
in your next run of jupyter lab
/ jupyter notebook
Note :
If you have installed nb_conda_kernels
, and want to create a new conda environment and have it accessible right away then
conda create -n new_env_name ipykernel
will do the job.
How to connect R conda env to jupyter notebook
Jupyter does not automatically recognize Conda environments, activated or not.
Kernel Module
First, for an environment to run as a kernel, it must have the appropriate kernel package installed. For R environments, that is r-irkernel
, so that one needs 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 one has 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 environments. This must be installed in the environment that has jupyter
installed (only one installation is needed!), for example, if this is base, then
conda install -n base nb_conda_kernels
Please read the documentation for details.
If using a system-level installation of Jupyter (i.e., not installed by Conda), then one needs to manually register the kernel. For example, something like
conda run -n r_venv_conda Rscript -e 'IRkernel::installspec(name="ir33", displayname="R 3.3")'
where one can set arbitrary 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 environment that should be activated before running jupyter notebook
. The kernel will be available to select from within Jupyter.
Related Topics
Return and Yield in the Same Function
How to Make a Barplot and a Lineplot in the Same Seaborn Plot with Different Y Axes Nicely
Oserror: [Winerror 193] %1 Is Not a Valid Win32 Application
How to Break Up This Long Line in Python
How to Import a Text File on Aws S3 into Pandas Without Writing to Disk
Checking File Permissions in Linux with Python
How to Read File with Space Separated Values in Pandas
Differencebetween 'Transform' and 'Fit_Transform' in Sklearn
Removing Elements from a List Containing Specific Characters
How to Remove Duplicate Words in a String with Python
Generate a List of Datetimes Between an Interval
How Does Keras Calculate the Accuracy
List Comprehension and Lambdas in Python
Reduce Left and Right Margins in Matplotlib Plot
Get an Attribute Value Based on the Name Attribute with Beautifulsoup
How to Convert Column with List of Values into Rows in Pandas Dataframe
Sql-Like Window Functions in Pandas: Row Numbering in Python Pandas Dataframe
Case-Insensitive List Sorting, Without Lowercasing the Result