可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
Solution: Do not use "tensorflow" as your filename.
Notice that you use tensorflow.py as your filename. And I guess you write code like:
import tensorflow as tf
Then you are actually importing the script file "tensorflow.py" that is under your current working directory, rather than the "real" tensorflow module from Google.
Here is the order in which a module will be searched when importing:
The directory containing the input script (or the current directory when no file is specified).
PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
The installation-dependent default.
回答2:
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:
- I removed tensorflow-gpu, tensorflow, tensorflow-base packages from Anaconda. Using. conda remove tensorflow-gpu tensorflow tensorflow-base
- re-installed tensorflow. Using conda install tensorflow
回答3:
Faced same issue on Ubuntu 16LTS when tensor flow was installed over existing python installation.
Workaround: 1.)Uninstall tensorflow from pip and pip3 sudo pip uninstall tensorflow sudo pip3 uninstall tensorflow
2.)Uninstall python & python3 sudo apt-get remove python-dev python3-dev python-pip python3-pip
3.)Install only a single version of python(I used python 3) sudo apt-get install python3-dev python3-pip
4.)Install tensorflow to python3 sudo pip3 install --upgrade pip
for non GPU tensorflow, run this command
sudo pip3 install --upgrade tensorflow
for GPU tensorflow, run below command sudo pip3 install --upgrade tensorflow-gpu
Suggest not to install GPU and vanilla version of tensorflow