Jupyter Notebook not recognizing packages in the newly added kernals

Viewed 2333

I have anaconda base environment and 1 other environment where i have tensorflow installed which i am trying to import in my jupyter notebook after changing the kernel.

i installed jupyter notebook in my conda base environment using the following command:

conda install -c conda-forge jupyterhub and by simply doing: pip install jupyter

after that i added my new environment with tensorflow and some other additional packages with this command: python -m ipykernel install --user --name env_cod --display-name "Python (env_cod)"

So now i launch jupyter notebook by simple (jupyter-notebook) in the desired directory and i also tried launching jupyter-notebook after activating the env_cod environment from terminal. But still i am not able to import tensorflow in my jupyter notebook after changing the kernal by selecting from the kernel tab also when i create new jupyter notebook by selecting env_cod environment i am not able to import tensorflow and get this error : no module named tensorflow

I already tried uninstalling and installing jupyter in my both base and env_cod environment.

Also there is nothing wrong with my env_cod environment and tensorflow is working perfectly fine along with other packages when i run my scripts through PyCharm after selecting env_cod environment. The Problem is Only with Jupyter Notebook.

1 Answers

Solved it by editing the .jason file and providing the right path to the environment executable.

Edit.

all i did was to go into C:\Users\YOUR_USERNAME\AppData\Roaming\jupyter\kernels and you will find all the kernels which you added into Jupyter Notebook.
Now just go to folder which is not loading the correct Python Executable and you will find kernel.json file in that folder.
Open that file

{
 "argv": [
  "D:\\Path\\To\\Correct\\python.exe",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "ENV_NAME",
 "language": "python"
}

For some reason the path to python executable was of my Base Python Environment so i changed it to my Virtual Environment's Python Executable Path and after that it loads the correct environment in my Jupyter Notebook.

Related