0

I installed tensorflow using conda in wsl, and now I'm using it through Jupyter notebook and it's working fine. I also write codes in vscode and then run it through wsl using python3 filename.py and it works fine too. the problem is when I try to run the code using the 'running' option of vscode and then I get the error ModuleNotFoundError: No module named 'tensorflow' in terminal. I checked my environments and I only have 'base' environment so the packages should be installed there and I also tried 'conda ...' in vscode terminal and it didn't recognize conda either. what can be the problem with my vscode?

also I have to say that numpy and matplotlib packages are running fine using vscode itself but tensorflow and some other modules are not identified

fatemeh_p
  • 21
  • 4

1 Answers1

0

You need to create a new virtual environment in anaconda to install Tensorflow and can access the Visual Studio code from the same virtual environment.

Open anaconda prompt and type below code to create virtual environment

conda create -n tf tensorflow
conda activate tf

install TensorFlow in that "tf" virtual environment

pip install tensorflow

launch VS code by selecting the same "tf" virtual environment in anaconda navigator.

Now, type the below code to check if TensorFlow installed successfully in VS code.

import tensorflow as tf
print(tf.__version__)

Likewise, you can install other required packages in the same virtual environment.

pip install <package-name>