TensorFlow, "module" does not have the "placeholder" attribute

I try to use tensorflow for two days, installing and reinstalling it again and again in python2.7 and 3.4. No matter what I do, I get this error message when trying to use tensorflow.placeholder ()

This is very boilerplate code:

tf_in = tf.placeholder("float", [None, A]) # Features 

No matter what I do, I always get a trace back:

 Traceback (most recent call last): File "/home/willim/PycharmProjects/tensorflow/tensorflow.py", line 2, in <module> import tensorflow as tf File "/home/willim/PycharmProjects/tensorflow/tensorflow.py", line 53, in <module> tf_in = tf.placeholder("float", [None, A]) # Features AttributeError: 'module' object has no attribute 'placeholder' 

Does anyone know how I can fix this?

+18
python machine-learning tensorflow
source share
9 answers

It happened to me too. I had a flow tensor and it worked pretty well, but when I set the gpu-flow tensor along the previous flow tensor, this error occurred, then I followed these 3 steps and it started working without problems:

  1. I removed tenorflow-gpu, tenorflow, tensor flow base packages from Anaconda. Through. Konda remove Tensor-GPU Tensor-flow Tensor-base
  2. reinstalled the flow tensor. Using conda, install tenorflow
+10
source share

Decision. Do not use "tensor flow" as the file name.

Note that shadoworflow.py is used as the file name. And I think you are writing code like:

 import tensorflow as tf 

Then you actually import the script file "tensorflow.py" that is under your current working directory, and not the "real" tensor flow module from Google.

The following is the order of module search during import:

  • The directory containing the script input (or the current directory if no file is specified).

  • PYTHONPATH (a list of directory names, with the same syntax as the PATH shell variable).

  • Installation-specific value.

+36
source share

If you get this error after upgrading to TensorFlow 2.0, you can still use API 1.X by replacing:

 import tensorflow as tf 

by

 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() 
+13
source share

It seems that .placeholder () ,. reset_default_graph () and others were removed with version 2. I ran into this problem using the Docker image: tensorflow/tensorflow:latest-gpu-py3 , which automatically pulls the latest version. I worked in version 1.13.1, automatically "upgraded to 2" and began to receive error messages. I fixed this by refining my image: tensorflow/tensorflow:1.13.1-gpu-py3 .

More information can be found here: https://www.tensorflow.org/alpha/guide/effective_tf2

+4
source share

Faced the same issue on Ubuntu 16LTS when the tensor thread was installed on top of an existing python installation.

Workaround: 1.) Remove tensor flow from pip and pip3 sudo pip remove tensor sudo pip3 remove tensor flow

2.) Remove python and python3 sudo apt-get remove python-dev python3-dev python-pip python3-pip

3.) Install only one version of python (I used python 3) sudo apt-get install python3-dev python3-pip

4.) Install tenorflow on python3 sudo pip3 install --upprade pip

for a tensor without a GPU, run this command

sudo pip3 install --dimensional tensor flow

for the GPU strain gauge, run the command below sudo pip3 install --upgrade tenorflow-gpu

Suggest not to install GPU and vanilla version of tensor stream

+1
source share

It could be a typo if you misspelled the word placeholder . In my case, I mistakenly placehoder it as a placehoder and got an error like this: AttributeError: 'module' object has no attribute 'placehoder'

0
source share

I got the same error too. Maybe because of the tenorflow version. After installing tenorflow 1.4.0, I got relief from the error.

 pip install tensorflow==1.4.0 
0
source share

If you are using TensorFlow 2.0, then the code developed for tf 1.x may work. Or you can follow the link: https://www.tensorflow.org/guide/migrate

or you can install the previous version of TF pip3 install tenorflow == version

0
source share

Since you cannot use the placeholder of the enemy tenensflow2.0, you need to use tenflow1 *, or you need to change the code to fix tensflow2.0

0
source share

All Articles