tensorflow 出错module 'tensorflow' has no attribute 'layers'

出错:module 'tensorflow' has no attribute 'layers'

解决方法:由于已经安装的tensorflow是0.x的版本,0.x版本没有layers模块所以程序出错,需要重新安装tensorflow 1.0以上的版本,即更新tensorflow版本。

查看目前tensorflow版本

pip list

显示:如下图,此时的tensorflow为0.12.0版本

tensorflow 出错module 'tensorflow' has no attribute 'layers'

所以需要更新版本号。

cpu版本更新:

升级方法

1、首先**tensorflow环境(我的环境命名是grey)

activate grey


2、输入以下安装命令: 
GPU版本:

pip install --upgrade tensorflow-gpu


CPU版本:

pip install --upgrade tensorflow


博主为cpu版本,输入pip install --upgrade tensorflow后回车就开始升级过程,会下载并卸载重装一些必要的包,时间长短视网速而定。

tensorflow 出错module 'tensorflow' has no attribute 'layers'

经过几分钟的等待。更新完成:

tensorflow 出错module 'tensorflow' has no attribute 'layers'

启动spyder 重新运行tensorflow程序。

运行结果已经没有报错。

tensorflow 出错module 'tensorflow' has no attribute 'layers'

哈哈哈哈!大功告成!