Hi!
In yesterday post, I created a new virtual environment named [devtf] and in this environment I’ve installed a lot of tools that I need. Then I tried to launch a jupyter notebook from this environment, to use this tools and, of course, it didn’t work.

It was time to read and learn how this works. So, when I finally get this I find this amazing article which really explain how this works “Using Virtual Environments in Jupyter Notebook and Python” (see references)
Jupyter Notebook makes sure that the IPython kernel is available, but you have to manually add a kernel with a different version of Python or a virtual environment. First, you need to activate your virtual environment. Next, install ipykernel which provides the IPython kernel for Jupyter. And finally, you can add your virtual environment to Jupyter.
So the commands are
pip install --user ipykernel
python -m ipykernel install --user --name=devtf
Where “devtf” is the name of the new kernel you want to create. Now, when I launch Jupyter Notebooks, the new kernel is available to be used

When I started to use this new kernel (virtual environment) I realized that I didn’t installed TensorFlow. You know, being happy about this, naming the kernel TF but not installing the core component. And, sure, my notebooks didn’t work.

I went to my terminal / command prompt and installed TensorFlow. Then I only need to restart the Kernel, and everything start working. I added a extra couple of lines in my notebook just to check the TensorFlow and keras versions.

I find similar errors with another packages, so I pip installed the packages in the terminal and restart the kernel to have the notebook OK. So, my simple reminder for myself about how to do this!
Happy coding!
Greetings @ Mississauga
El Bruno
References
- Can’t install TensorFlow on Anaconda, maybe is the Visual Studio distribution https://elbruno.com/2019/09/09/python-cant-install-tensorflow-on-anaconda-maybe-is-the-visual-studio-distribution/
- Using Virtual Environments in Jupyter Notebook and Python , https://janakiev.com/blog/jupyter-virtual-envs/
2 comments