'Tensorflow is partially imported

When I run a script and import Tensorflow from cmd or Visual Studio Code it throws me the error enter image description here

but when I run it from Anaconda prompt or Spyder it works well. Why does this happen??? DO I have to add anything to PATH?



Solution 1:[1]

This is due to Python and TensorFlow being installed only in your anaconda environment.

  1. To access TensorFlow from command prompt rather than anaconda prompt , you need to follow the steps below:

Open command prompt as administrator (by right click and selecting run as administrator)

C:\windows\system32\python   # (This will show if python is installed in this directory or can install the latest python)
C:\windows\system32\pip install --upgrade pip 
C:\windows\system32\pip install tensorflow (to install tensorflow in same path)
C:\windows\system32\python>>import tensorflow as tf >>print(tf.__version__) #to check if tensorflow installed successfully an dis accessible
  1. To access TensorFlow through VS code, you need to install python extension for VS code after installing VS code in your system. After successful installation of extension, you can click on "Create new Jupyter notebook" and select the appropriate Python interpreter as in Anaconda.

Now the VS code is ready to run TensorFlow code. Please check this link for your reference.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer2