renatodamas
renatodamas

Reputation: 19515

Installing python kernel in a Conda environment

I have just started using jupyter notebook for my development process. I started by creating a new python environment:

$ conda create -n testenv

Then I activate it:

$ source activate testenv

And install python kernel module:

$ pip install ipykernel

Now that's when the fuzziness begins. I want to create a new kernel specifically to my active environment only. Following documentation, I did:

$ python -m ipykernel install --user --name testenv --display-name "Python (testenv)"

With this I believe I have just created a new Python kernel for the testenv environment to be used within Jupyter Notebook. Now, I want to confirm this information and I check:

$ jupyter kernelspec list

Available kernels:
testenv   /home/{{user}}/.local/share/jupyter/kernels/testenv
python2   /home/{{user}}/miniconda2/share/jupyter/kernels/python2

$ conda env list
# conda environments:
#
base         /home/{{user}}/miniconda2
testenv   *  /home/{{user}}/miniconda2/envs/testenv

I was expecting to see my kernel installed within the testenv environment, something like:

/home/{{user}}/miniconda2/envs/testenv/kernels/testenv

I am failing to see how do the environments and kernels tie together and how can I confirm this information.

Upvotes: 5

Views: 20028

Answers (4)

Vinay Badewale
Vinay Badewale

Reputation: 1

To install Kernel

Go to anaconda prompt and execute the following command

ipython kernel install --user --name={envionment name}

Upvotes: 0

MHX
MHX

Reputation: 1

Do what you did, but in the kernel installation step, replace --user with --sys-prefix, that is:

python -m ipykernel install --sys-prefix --name testenv --display-name "Python (testenv)"

then the kernel would be installed in the path you intended to:

/home/{{user}}/miniconda2/envs/testenv/kernels/testenv

Upvotes: 0

Bernarddo
Bernarddo

Reputation: 19

First of all you need to use the following:

conda create -n testenv

After you should use:

conda activate testenv
conda install ipykernel
python3 -m ipykernel install --user --name condaenv --display-name "Python3 (testenv)"

Once you have done this, you could start up the notebook by using jupyter notebook and opens any .ipynb notebook. Inside that notebook, select the menu Kernel > Change kernel > Python3 (condaenv) to activate the conda environment kernel.

Upvotes: 2

darthbith
darthbith

Reputation: 19617

The problem is that when you create the empty environment, it installs absolutely no packages, even pip and Python. Therefore, when you use pip to install ipykernel, you're using the pip from the base environment. You need to create the environment with pip and python

conda create -n testenv python

You can check this by typing

which pip

after you create the blank environment.

Finally, you should use conda to install all packages, including ipykernel, if at all possible.

Upvotes: 2

Related Questions