<module 'tensorflow._api.v2.version' from '/usr/local/lib/python3.6/dist-packages/tensorflow/_api/v2/version/__init__.py'> code example

Example 1: AttributeError: module 'tensorflow._api.v2.train' has no attribute 'GradientDescentOptimizer'

Use version for the TensorFlow 2.x:

tf.optimizers.SGD (learning_rate=0.001, name='SGD')

Example 2: tensorflow_core._api.v2.train' has no attribute 'GradientDescentOptimizer'

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()