johnwow
johnwow

Reputation: 767

Cannot import tensorflow in vscode

enter image description here I have installed tensorflow in a virtual environment and can import Tensorflow in jupyter notebook or terminal. I am now learning to use VScode, so I try to launch it in the jupyter notebook within the VScode, but Tensorflow cannot be imported.

It shows ModuleNotFoundError: No module named 'tensorflow', but I have installed it and it can be used in the terminal or jupyternotebook.

I also tried to define the path of the python interpreter, but it did not work. Could someone help me out? Tons of thanks.

Upvotes: 3

Views: 10058

Answers (4)

Shree Harsha
Shree Harsha

Reputation: 1

Without NVIDIA GPU which needs the requirements as mentioned in the website, I don't think that it will be downloaded from the terminal if you don't have an external GPU or so

Upvotes: 0

Alexis
Alexis

Reputation: 1603

Windows 10, python 3.10, tensorflow-gpu 2.10 installed in a V310_TF virtual environment.

I specifically selected the good interpreter in VsCode CTRL+SHIFT+P > Python: clear workspace interpreter settings (CTRL+SHIFT+P) > Select interpreter ... . The status bar at the bottom was updated accordingly pointing to V310_TF.

However, VsCode was still pointing to another interpreter in another virtual environment that i used the same day. I discovered it using

import sys
sys.executable
>>...\\v311_ANOTHER_ENV\\Scripts\\python.exe'  

So the powershell instance in VsCode was not pointing where it was intended.

I restarted VsCode and it solved the problem.

Upvotes: 0

I'm using python 3.11.x and Win 11 then is working fine when I've imported as this:

import tensorflow as tf
from tensorflow.python.keras.layers import Dense 
from tensorflow.python.keras.layers.recurrent import LSTM as LSTM_keras
from tensorflow.python.keras.models import Sequential

bye

Upvotes: 0

Harsh gupta
Harsh gupta

Reputation: 190

Try:

This works for me.

pip --version

python -m pip install --upgrade pip

pip3 install tensorflow==2.0.0

Upvotes: 1

Related Questions