- 寫老師佈置的神經網絡作業中,要求安裝tensorflow,並且運行示例代碼(使用with tf.Session()創建上下文)
- 我作爲新手,本來想在Ubuntu上弄的,奈何電腦有點帶不動虛擬機各種報bug。最後還是老老實實的在我的win10上安裝了anaconda。官網:https://www.anaconda.com/。
- 最後在anaconda神器的圖形界面上安裝tensorflow
- 安裝成功之後,開始運行老師給的示例代碼:
import tensorflow as tf
hello=tf.constant('hello world!')
with tf.Session() as sess:
-
`print(sess.run(hello).decode())`
- 結果報錯:AttributeError: module ‘tensorflow’ has no attribute ‘Session’
10.查了蠻久,一開始看的是英文的回答,半天沒看懂,後來終於翻到國內網友的解答才明白。意思就是說更新的tensorflow已經刪除了Session ,tf.Session()已過時,需要使用tf.compat.v1.Session()代替。即把上面第三行替換爲
:with tf.compat.v1.Session() as sess:
- 現在運行代碼就對了
AttributeError: module 'tensorflow' has no attribute 'Session'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.