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

2
  • Does nlp have ipykernel installed? You can check with conda list -n nlp ipykernel. Commented Nov 27, 2019 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 ``` Commented Nov 27, 2019 at 16:32

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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/<username>/Library/Jupyter/kernels/nlp ```
No, it is macOS
Could you please try creating a new conda environment and try installing ipykernel in that environment using the above steps
1

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.

1 Comment

Thanks. This helped resolve my issue. I had to reinstall jupyter.
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]"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.