AttributeError: module 'tensorflow' has no attribute 'constant'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liyangyang08/article/details/81160100

写在前面的话

  • 最近tensorflow 安装完后测试了一下没有问题,准备用vscode进行安装。然后配置了文件
  • 首选项-> 设置
"python.pythonPath": "C:\\Users\\lyy08\\Anaconda3\\envs\\tensorflow\\python.exe",
    "python.autoComplete.extraPaths": [
        "C:\\Users\\lyy08\\Anaconda3\\envs\\tensorflow",
        "C:\\Users\\lyy08\\Anaconda3\\envs\\tensorflow\\Lib\\site-packages"
    ],
    "workbench.statusBar.visible": true,
    "files.autoGuessEncoding": true,
    "python.autoComplete.addBrackets": true,
    "python.autoComplete.preloadModules": [
        "tensorflow"
    ],
    "python.linting.pep8Enabled": true,
    "python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
    "python.linting.pep8Args": ["--ignore=E303"],
    "editor.fontSize": 18,
    "terminal.integrated.rendererType": "dom"

然后运行得到标题错误,尝试了如下的几种办法

  1. 重装 参考https://stackoverflow.com/questions/37383812/tensorflow-module-object-has-no-attribute-placeholder

  2. 是不是tensorflow.py文件冲突,查找了一下envs文件下只有一个。 然后进命令行验证一下发现正常这里写图片描述

  3. 放弃了这个想法,后来无意看到了一个解决方案这里写图片描述
    于是改一下文件名为tf.py

正常了

这里写图片描述

猜你喜欢

转载自blog.csdn.net/liyangyang08/article/details/81160100