# [SOLVED] - AttributeError: module 'tensorflow' has no attribute 'placeholder'

Quote from lukasz.ciesla on January 12, 2020, 12:09 pmThe cause of the mentioned problem is incompatibile code with installed tensorflow library. In this case you have code compatible with tensorflow 1.0 version but installed tensorflow 2.0 or higher. Let's see what you can do to solve the problem.

## Solution 1. Follow tensorflow migration guide

Migrate your code following this guide. Solution for the title problem is to use

variablesinstead ofplaceholders. Let's see the following example:

[adinserter block="1"]

#tensorflow 1.x self._states = tf.placeholder(shape=[None, self._num_states], dtype=tf.float32) #tensorflow 2.x self._states = tf.Variable(tf.ones(shape=[None, self._num_states]), dtype=tf.float32)## Solution 2. Use tensorflow 1.x compatibility mode

The second approach is to use tensorflow v1 copatiblity mode. To dot his you have to use

instead ofimport tensorflow.compat.v1 as tfand addimport tensorflow as tf.tf.disable_v2_behavior()import tensorflow as tf x = tf.placeholder(shape=[None, 2], dtype=tf.float32)import tensorflow.compat.v1 as tf tf.disable_v2_behavior() x = tf.placeholder(shape=[None, 2], dtype=tf.float32)

The cause of the mentioned problem is incompatibile code with installed tensorflow library. In this case you have code compatible with tensorflow 1.0 version but installed tensorflow 2.0 or higher. Let's see what you can do to solve the problem.

## Solution 1. Follow tensorflow migration guide

Migrate your code following this guide. Solution for the title problem is to use *variables* instead of *placeholders*. Let's see the following example:

[adinserter block="1"]

#tensorflow 1.x self._states = tf.placeholder(shape=[None, self._num_states], dtype=tf.float32) #tensorflow 2.x self._states = tf.Variable(tf.ones(shape=[None, self._num_states]), dtype=tf.float32)

## Solution 2. Use tensorflow 1.x compatibility mode

The second approach is to use tensorflow v1 copatiblity mode. To dot his you have to use * import tensorflow.compat.v1 as tf* instead of

*and add*

**import tensorflow as tf***.*

**tf.disable_v2_behavior()**import tensorflow as tf x = tf.placeholder(shape=[None, 2], dtype=tf.float32)

import tensorflow.compat.v1 as tf tf.disable_v2_behavior() x = tf.placeholder(shape=[None, 2], dtype=tf.float32)