1. 程式人生 > >AttributeError: module 'tensorflow' has no attribute 'constant'

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

寫在前面的話

  • 最近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

正常了

這裡寫圖片描述