Python how to use tensorflow-cpu

Viewed 1330

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.

1 Answers

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

import tensorflow as tf
Related