How do I get tensorflow to work in VS Code?

Hi all

So I had lots of trouble getting tensorflow to work in jupyter notebook, but after much trial and error and installing it in several different places not knowing what I was doing, I did what this guy said and it worked:
https://www.youtube.com/watch?v=CMYE6wMBx40

He basically says to install tensorflow in anaconda, and then change from the base (root) environment to the tensorflow environment that we create and launch jupyter notebook from there, as shown in these images:
What I click:

Proof that tensorflow works in jupyter notebook now:
image

Now I want tensorflow to work in VS Code, but following the same route as before doesn’t work. I go into the tensorflow/tf environment I created in anaconda, launch VS Code from there, open a jupyter notebook file in VS Code and it doesn’t work:
What I click:

Proof it doesn’t work:

So now that you know the story, my question is (and I’m crossing my fingers tightly hoping that someone knows how all this installing business works and why):

  • How do I get tensorflow to work in VS Code?

Thanks for your time

Jaime

1 Like

Not sure if you have checked this, try selecting the interpreter(python env with TensorFlow) in the notebook editor, as mentioned here
Working with Jupyter Notebooks in Visual Studio Code

1 Like

Thank you @manimaran_p, your suggestion worked! I didn’t realise I could choose a kernel with the tf environment (probably because I don’t know what the environment or the kernel are). Could you explain this by any chance?

Thanks for your time

Jaime

@JaimeGGB as @manimaran_p suggested, try following the steps in the section mentioned above (selecting a kernel using a “kernel picker” in VS Code Jupyter notebook)


Let us know if this helps:

  • Python environments:
  • Kernels:

https://ipython.readthedocs.io/en/stable/install/kernel_install.html

  • Kernels and envs:
1 Like

This is the first time JaimeGGB has posted — let’s welcome them to our community!

And welcome @JaimeGGB :tada:

Welcome

1 Like

We have a WIP preconfiguration for Vsocde at:

You could easily change the image type at:
https://github.com/tensorflow/tensorflow/pull/51439/files#diff-24ad71c8613ddcf6fd23818cb3bb477a1fb6d83af4550b0bad43099813088686R9

With one of the official jupyter image in the list:
https://hub.docker.com/r/tensorflow/tensorflow/tags?page=1&name=jupyter

1 Like

I found the solution for my Vscode with these update code “pip”
conda create -n tensorflow python=3.5
activate tensorflow
pip install --ignore-installed --upgrade tensorflow
If the python version is not 3.5 in your actual environment in vscode , please change the version number.

Thanks @Duong_Tran_Minh :+1:

Which TF version did you managed to install?

As per https://www.tensorflow.org/install:

TensorFlow is tested and supported on the following 64-bit systems:

  • Python 3.7–3.10

cc @markdaoust

Hi. My base version in Vscode is 3.8.