"No module" after setting up jupyter kernel

Question:

I installed tensorflow using the official instructions:

conda create -n tf-gpu tensorflow-gpu

If I activate the kernel, I can see tensorflow is installed.

conda activate tf-gpu
python3 -c 'import tensorflow as tf; print(tf.__version__)'

It returns the following.

2022-03-24 01:21:50.006341: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2.4.1

Now I want to have tf-gpu recognized as a kernel in jupyter notebook.

conda deactivate tf-gpu
python -m ipykernel install --user --name=tf-gpu

However, when I launch jupyter notebook

jupyter notebook

The created tf-gpu notebook does not work as expected.

import tensorflow

Returns the following error

ModuleNotFoundError: No module named 'tensorflow'

Why is the package not being recognized?

Asked By: Joseph

||

Answers:

You need to make a new kernel for this env and select the kernel from jupyter notebook as follows:

conda activate env_name
pip install ipykernel --user
python -m ipykernel install --user --name env_name --display-name env_name

Then open the notebook >> click on kernel >> change kernel >> select the kernel.

Let us know if the issue still persists. Thanks!

Answered By: Tfer3

Or you can also use ipython kernel instead of ipykernel after installation as shown below:

ipython kernel install --user --name env_name --display-name env_name

Answered By: Yashashvi