tensorflow踩坑分享:AttributeError: module 'tensorflow' has no attribute 'xxx'
一、环境
windows10
python3.6
tensorflow-gpu1.14
二、前因
前段时间开始学习tensorflow,后因事搁置,前几天重新学习,一开始使用没什么问题,后需要加装别的包,搞到环境有点乱,且此时已经出现了如题 AttributeError: module ‘tensorflow’ has no attribute ‘xxx’ 的问题。所以重新新建了一个conda的虚拟环境,但问题仍然存在。
三、解决过程
(一)问题表现:
import tensorflow as tf 可以成功,但是不管是 tf.Variable 还是 tf.placeholder 均会报如题错误。
(二)问题排查:
此时 tf.__path__ 仍可以使用,利用 tf.__path__ 可以查询到tensorflow的路径。
经查询,路径并非导向conda虚拟环境(一般为:C:\Users\用户名\Anaconda3\envs\环境名 路径下的一堆东西),而是导向了本地环境的路径(在我这里是 C:\Users\用户名\AppData\Roaming\Python\Python36\tensorflow)
该路径下的tensorflow是2.0版本,应该是我装环境是误操作装上,后续pycharm导入时