7

I am not able to link Jupyter kernels to their parent Conda environments. After creating a new kernel linked to Conda environment, I'm getting a different version of Python and its dependencies inside Jupyter lab.

Here are the steps I followed:

Created a conda environment using:

conda create -n nlp python=3.6

conda activate nlp

(nlp) ➜ ~ python --version

Python 3.6.9 :: Anaconda, Inc.

(nlp) ➜ ~ which python

/anaconda3/envs/nlp/bin/python

Inside the environment I created a Jupyter kernel with:

(nlp) ➜ ~ python -m ipykernel install --user --name=nlp

Installed kernelspec nlp in /Users//Library/Jupyter/kernels/nlp

Investigating the created json file for the kernel:

(nlp) ➜  ~ cat /Users/<username>/Library/Jupyter/kernels/nlp/kernel.json
{
 "argv": [
  "/anaconda3/envs/nlp/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "nlp",
 "language": "python"
}%

It seems to be pointing to the environment version of Python

But when I start Jupyter Lab and select the nlp kernel, I get a different version of Python and some dependencies are missing

!python --version

Python 3.5.6 :: Anaconda, Inc.

!which python

/anaconda3/bin/python

amrakm
  • 83
  • 1
  • 6
  • Does `nlp` have `ipykernel` installed? You can check with `conda list -n nlp ipykernel`. – merv Nov 27 '19 at 15:48
  • 1
    Yes, `ipykernel` installed, the output of your command: ``` # packages in environment at /anaconda3/envs/nlp: # # Name Version Build Channel ipykernel 5.1.3 py37h39e3cac_0 ``` – amrakm Nov 27 '19 at 16:32

3 Answers3

4

Could you please try the following steps:

conda activate nlp
conda install ipykernel
ipython kernel install --name nlp --user 

After these steps please try changing the kernel again in jupyter lab to "nlp".

Thanks.

Lakshmi - Intel
  • 581
  • 3
  • 10
  • 1
    This didn't work ``` (nlp) ➜ ~ conda install ipykernel Solving environment: done # All requested packages already installed. (nlp) ➜ ~ ipython kernel install --name nlp --user Installed kernelspec nlp in /Users//Library/Jupyter/kernels/nlp ``` – amrakm Nov 27 '19 at 09:19
  • 1
    No, it is macOS – amrakm Nov 27 '19 at 16:30
  • Could you please try creating a new conda environment and try installing ipykernel in that environment using the above steps – Lakshmi - Intel Nov 28 '19 at 05:32
0

this behavior is actually normal in Jupyter lab. If you run

import sys
print(sys.version)
!python --version

in a notebook, the print statement will give you the Python version of the conda env, while the second will give you the Python version of your base env.

The easiest workaround for this is to simply pip install jupyterlab in your conda env and then run jupyter lab in your conda env. Then, there will not be a mismatch in Python versions between the new "base" env and the conda env which will help clear up any DLL problems.

It's probably not best practice, but you do what you gotta do when working with legacy code, ig.

nutrition
  • 1
  • 1
0

Can you try this :

# in base env
conda install nb_conda_kernels
conda activate nlp
conda install ipykernel
conda install ipywidgets
# install kernelspec
python -m ipykernel install --user --name nlp --display-name "nlp env"

When you run jupyter notebook, you will see 2 nlp kernels. Use the one with "Python [conda:env:nlp]"

J R
  • 436
  • 3
  • 7