skip to Main Content

I’m seeking to use tensorflow with conda in a anaconda3 python notebook within VSCode.
In the anaconda terminal, on a Windows 10 machine, I used the following commands:

conda create --name deeplearning
activate deeplearning
conda install -c conda-forge tensorflow
conda install -c anaconda jupyter
conda install -c anaconda pandas
conda install -c conda-forge matplotlib
conda install -c anaconda scikit-learn

I checked the Anaconda navigator to make sure that all of the files were installed.

I then went to visual studio code, hit Ctrl - Shift - p and selected Python: Select Interpreter and hit Python 3.7.16 ('deeplearning') ~anaconda3envsdeeplearningpython.exe. deeplearning was shown to be active.

While from matplotlib import pyplot as plt worked fine, commands such as import tensorflow as tf resulted in the following error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[11], line 1
----> 1 import tensorflow as tf

ModuleNotFoundError: No module named 'tensorflow'

Same thing happened with import tensorflow_datasets as tfds.

I’ve tried restarting the computer, as well as deleting and remaking the environment. Nothing is working.

How do I get my environment to work properly in VSCode, allowing me to use tensorflow?

2

Answers


  1. From your error page it is clear that you should be using Jupyter, which is different from .py scripts. You can click on the kernel version displayed in the top right corner of the jupyter interface to select Python 3.7.16 ('deeplearning') , which is the setting made for jupyter.

    enter image description here

    Python: Select Interpreter values are specific to the settings for .py script files.

    Login or Signup to reply.
  2. There are two separate ways of selecting Interpreters.

    If you are using python scripts that is .py files then your way would work.
    If you are using a Python Notebook, then you need to select the kernel as shown in the image below.

    Select Kernel on VSCode

    Select Python Environment

    Select your kernel

    That should set your notebook to your environment you created in anaconda.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search