Tensorflow running on terminal but not with my code editor

Issue

I have created a venv and installed the tenserflow via pip, checked the versions and everything seems fine. However, when I want to run my code (simply import tensorflow) it pops the following error.

**ModuleNotFoundError: No module named 'tensorflow'**

I can’t use Keras as well because of that.
Something also caught my attention, when on terminal and venv active I run the same code on python3 and it does just fine. I am able to import Keras as well on terminal Python3.

What could be my problem? I have read almost every article and tried every possible solutions that can be found on the web.

System: MACOS Mojave
Python: 3.8.8
Pip: the latest
Code editor: Visual Studio Code

Solution

According to your description, please refer to the following:

  1. The location where the module is installed is not the python environment currently used by VS Code.

    Please use "pip --version" in the VS Code terminal to check whether the source of the module installation tool "pip" is the same as that shown in the lower left corner of VS Code.

    (If they are different, please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, it will automatically enter the selected environment.)

  2. Related files in the installation package of the module are damaged.

    Please uninstall the module "tensorflow" and reinstall it. (pip uninstall tensorflow pip install tensorflow)

  3. Please check the naming of the module installation package. (Please pay attention to the case of naming.)

    enter image description here

Reference: Python environments in VS Code.

Answered By – Jill Cheng

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published