2

I successfully installed tensorflow-cpu as pip install tensorflow-cpu

However, when trying to import the package, I am receiving this error on first line.

import tensorflow-cpu as tf
import numpy as np
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
l0 = Dense(units=1, input_shape=[1])
model = Sequential([l0])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
model.fit(xs, ys, epochs=500)

ERROR Line 1: No module named tensorflow.

How can I resolve this issue?

I don't have the updated GPU or NVIDIA Packages, not supported on my laptop, so it was recommended to utilize cpu version.

mattsmith5
  • 540
  • 4
  • 29
  • 67
  • if you are not using it, comment it out ` #import tensorflow-cpu as tf ` – simpleApp Apr 19 '21 at 03:06
  • yeah, I got it from tutorial but I still see error on third line, where its used @simpleApp – mattsmith5 Apr 19 '21 at 03:07
  • Possible duplicate of https://stackoverflow.com/q/37660312 – bad_coder Apr 19 '21 at 03:32
  • sorry , not sure which tutorial you are following. pls go through this post : https://stackoverflow.com/questions/52624703/difference-between-installation-libraries-of-tensorflow-gpu-vs-cpu . You would be okay just install pip install tensorflow, reference : https://www.tensorflow.org/install – simpleApp Apr 19 '21 at 03:38

1 Answers1

4

Regardless of the tensorflow flavor you install (CPU or GPU), you always import tensorflow just as tensorflow, as shown below:

import tensorflow as tf
Carlos Melus
  • 1,472
  • 2
  • 7
  • 12