Modulenotfounderror: No Module Named 'Tensorflow. Examples'

Modulenotfounderror: No Module Named 'Tensorflow. Examples'

When I import tensorflow

import tensorflow as tf

I don't get an error. However, I do get the error below. I'm using spyder if that helps.

As per other questions, I ensured up to date (v1.8) tensorflow using both conda and then pip installs. This didn't resolve the issue. Please assist.

import tensorflow.examples.tutorials.mnist.input_data as input_data

ModuleNotFoundError: No module named 'tensorflow.examples'
1

12 Answers

I think you should use like bellow on tensorflow 2

import tensorflow_datasets
mnist = tensorflow_datasets.load('mnist')
2

Use the following, it will download the data. It is from the tensorflow documentation

import tensorflow as tf
(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data()
1

Sometimes the TensorFlow examples are not pre-downloaded, so you might need to run the below command to install the examples from Github using the below code.

!pip install -q git+
0

To load the mnist dataset in Tensorflow 2.0:

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

Here is the reference: TensorFlow 2 quickstart for beginners

Another method(also works for locally saved dataset):

DATA_URL = '

path = tf.keras.utils.get_file('mnist.npz', DATA_URL)
with np.load(path) as data:
  train_examples = data['x_train']
  train_labels = data['y_train']
  test_examples = data['x_test']
  test_labels = data['y_test']

Here is the reference: Load NumPy data

Sometimes on downloading the TF, the example directory might not be available. You could rectify it by linking the 'example' directory from the GitHub repo into the tensorflow python wheel folder. That way you don't need to change the code.

If this doesn't work, try to replace import tensorflow.examples.tutorials.mnist.input_data as input_data as import input_data as mentioned in the link: TensorFlow MNIST example not running with fully_connected_feed.py

Hope this helps!!!

1

I solved this issue by adding **tutorial** directory into tensorflow_core, usually this issue pops up when lacking of this file

  1. ..\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples check this directory to see if you have tutorials file. lack of tutorial file
  2. If you do not have, then go to download the zip file, and extract all (or open it). download tutorial file
  3. find tutorials file from tensorflow-master\tensorflow\examples\, and copy it to ..\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples.
  4. Issue resolved. run
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
im = mnist.train.images[1]
im = im.reshape(-1, 28)
plt.imshow(im)

Different approach OS: Windows

copy from:

to

[python folder]\Lib\site-packages\tensorflow_examples

use

import tensorflow_examples

example

from tensorflow_examples.models import pix2pix

but for datasets use:

pip install tensorflow_datasets

I solved this issue on Mac, simply copy the official examples to tensorflow_core/examples directory.

  1. pull the tensorflow code

    git clone

  2. copy the examples to the system python3 directory

    cp -a tensorflow/examples/ /usr/local/lib/python3.7/site-packages/tensorflow_core/examples/

0

You need to download the data sets to use it.

Command:

pip install tensorflow-datasets

Code part:

mnist_train = tfds.load(name="mnist", split="train")

You are done now. Happy coding! :)

You just need to download the lost files and copy them to the tensorflow-core/ examples.

for me on windows 10 is : C:\Users\Amirreza\AppData\Local\Programs\Python\Python37\Lib\site-packages\tensorflow_core\examples

This folder has been deleted at September/2020. See their repository.

I used the commands:

git clone 
tensorflow> git checkout c31acd156c

I solved this issue by installing Keras according to this answer from different question:

I didn't have Keras installed and had to add it manualy

ImportError: No module named 'keras'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.