ModuleNotFoundError: No module named 'tensorflow'

I have already installed TensorFlow via pip however I’m still getting this error. For context, I am on Mac, Python version 3.10.9, and used the instructions at: Install TensorFlow with pip

From what I read online, I think it might be a problem with the environments I installed TensorFlow and python in, but I don’t know the exact issue and how to fix it. Would appreciate any help.

You probably have two (or more) Python interpreters installed, and used pip to install in one of them and then tried to run the other.

Can you please run these commands at the shell and tell us what output they give?

pip -V
which python

Thanks for the reply.

Yes I realized this was the problem, as when I try and import TensorFlow in a Jupyter notebook there is no error. When I used those commands, I saw that the python interpreter recognized by the terminal was anaconda3. However if I want to use the actual Python IDLE to write and run all my code (including TensorFlow), is there a way to do that? I would rather do everything there than in jupyter.

Try running this: python -m pip install tensorflow

If it doesn’t work, please copy and paste the full error message.

Still getting the same error:

Traceback (most recent call last):
File “<pyshell#0>”, line 1, in
import tensorflow as tf
ModuleNotFoundError: No module named ‘tensorflow’

For further reference, I am in zsh for terminal. I believe it is still detecting the Anaconda interpreter; when I check the python version in terminal, it says 3.9.13 even though my IDLE version is 3.10.10.

Still getting the same error:

Traceback (most recent call last):
File “<pyshell#0>”, line 1, in
import tensorflow as tf
ModuleNotFoundError: No module named ‘tensorflow’

We probaby need to see a full shell transcript of the pip install and
the python invocation (and ideally a and which python for further
verification).

Example here:

 [~]fleet2*> which python3
 /Users/cameron/bin-cs/python3
 [~]fleet2*> python3
 Python 3.10.6 (main, Aug 11 2022, 13:47:18) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import tensorflow
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 ModuleNotFoundError: No module named 'tensorflow'
 >>>
 [~]fleet2*> python3 -m pip install tensorflow
 Collecting tensorflow
   Downloading tensorflow-2.11.0-cp310-cp310-macosx_10_14_x86_64.whl (244.3 MB)
      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 244.3/244.3 MB 2.5 MB/s eta 0:00:00
 [... lots of required packages ...]
 Installing collected packages: tensorboard-plugin-wit, libclang, flatbuffers, termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard-data-server, rsa, pyasn1-modules, protobuf, opt-einsum, oauthlib, MarkupSafe, keras, h5py, grpcio, google-pasta, gast, cachetools, astunparse, absl-py, werkzeug, requests-oauthlib, google-auth, google-auth-oauthlib, tensorboard, tensorflow
 Successfully installed MarkupSafe-2.1.2 absl-py-1.4.0 astunparse-1.6.3 cachetools-5.3.0 flatbuffers-23.1.21 gast-0.4.0 google-auth-2.16.1 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.51.3 h5py-3.8.0 keras-2.11.0 libclang-15.0.6.1 oauthlib-3.2.2 opt-einsum-3.3.0 protobuf-3.19.6 pyasn1-modules-0.2.8 requests-oauthlib-1.3.1 rsa-4.9 tensorboard-2.11.2 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-2.11.0 tensorflow-estimator-2.11.0 tensorflow-io-gcs-filesystem-0.30.0 termcolor-2.2.0 werkzeug-2.2.3
 [~]fleet2*> python3
 Python 3.10.6 (main, Aug 11 2022, 13:47:18) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import tensorflow
 2023-02-23 11:11:38.872103: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
 >>>
 [~]fleet2*>

Cheers,
Cameron Simpson cs@cskk.id.au

I think by retrying the install so many times and creating many different conda environments, I am getting confused with where I am and what I am doing. Is there a way I can completely uninstall TensorFlow from my device and remove all of the conda environments I’ve created? I think it is best to just start again from scratch, with the right steps this time.

Also, I will no longer be using IDLE as I think a Jupyter notebook or VSCode are probably better anyway. Anyone know a good tutorial for downloading TensorFlow on Mac?

I am also getting this message when importing TensorFlow in Jupiter notebook:

2023-02-26 21:40:35.743426: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

What do I do about this?