Can't run Python code in Visual Studio Code with Jupyter - "Jupyter kernel cannot be started from 'Python 3.6.8 64-bit"

Viewed 24853

I've installed Jupyter extension in the latest Visual Studio: Visual Studio 1.3.01 64 Jupyter 1.1.4

As I am using tensorflow I need Python 3 64bit.

When I try to run simple code I get:

Jupyter kernel cannot be started from 'Python 3.6.8 64-bit ('tensorflow64': virtualenv)'. Using closest match Python 3.7.0 32-bit instead.

Code:

#%%
import tensorflow as tf

session = tf.Session()

hello = tf.constant("Hello from Milan.")
print(session.run(hello))

a = tf.constant(20)
b = tf.constant(22)

print('a + b = {0}'.format(session.run(a + b)))

All works fine if I Run code not using Jupyter from VS Code.

5 Answers

Message from Jupyter is not the best description of the issue, missing ipykernel package.

Fix was to install additional python package 'ipykernel' into virtual environment with Python 3.64 bit.

pip install ipykernel

Additional info: https://github.com/Microsoft/vscode-python/issues/3579

conda create --name test_env
conda activate test_env
conda install -c anaconda ipykernel
python -m ipykernel install --user --name=test_env

Or this You can run this it might work

ipython kernel install --user --name=ENVNAME

Simple installation is the best. While learning Python et-all I had installed many things in many different ways. It was a mess. Removed everything and did a fresh install only I used pyenv and pipenv. However pipenv does not work with the latest version which you can install using brew. Solution revert back to version 2018.10.13 using pip install. Then I discovered that pipenv was no longer recommended so, I removed it. Built a test project and could not get jupyter to run. Spent all day trying everything.

Solution was, remove the old version of pipenv and install the latest using brew. All is well.

However, I do like the features of pyenv like setting global etc.

You have to select and save the .ipynb file with VSCode indicating a kernel that is reachable from your Jupyter installation:

enter image description here

In my case installing anaconda and call following comments solves it:

conda create -n tf tensorflow
conda activate tf

Related