TensorFlow, “'module' object has no attrib

2020-02-02 12:00发布

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

It's very boilerplate code:

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

No matter what I do I always get the 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'

Anyone know how I can fix this?

15条回答
Juvenile、少年°
2楼-- · 2020-02-02 12:28

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

or you can install a previous version of tf by pip3 install tensorflow==version

查看更多
别忘想泡老子
3楼-- · 2020-02-02 12:29

It happened to me too. I had tensorflow and it was working pretty well, but when I install tensorflow-gpu along side the previous tensorflow this error arose then I did these 3 steps and it started working with no problem:

  1. I removed tensorflow-gpu, tensorflow, tensorflow-base packages from Anaconda. Using.

conda remove tensorflow-gpu tensorflow tensorflow-base

  1. re-installed tensorflow. Using

conda install tensorflow

查看更多
再贱就再见
4楼-- · 2020-02-02 12:30

Recent version 2.0 does not support placeholder. I uninstalled 2.0 using command: conda remove tensorflow. then I installed 1.15.0 using command: conda install -c conda-forge tensorflow=1.15.0. 1.15 is latest in version 1 series. You can change as per you wish and requirement. For seeing all version, use command: conda search tensorflow. It worked for Anaconda3 in Windows.

查看更多
登录 后发表回答