簡體   English   中英

模塊“張量流”沒有屬性“會話”無法解析

[英]module 'tensorflow' has no attribute 'Session' cannot resolve

請幫幫我! 我解決不了!

所以...我的 python 版本是 Python 3.5.6 和 Anaconda 版本是康達 4.8.3。 我正在使用 Jupyter Notebook。

我在 MacOS 上工作。

我創建了一個環境 tfdeeplearning:

conda create -n tfdeeplearning python=3.5

我已經安裝了以下內容:

1. conda install jupyter
2. conda install numpy
3. conda install pandas
4. conda install scikit-learn
5. conda install matplotlib
6. pip install --upgrade tensorflow 

因此,在 Jupyter Notebook 中,我嘗試運行以下代碼:

import tensorflow as tf 
hello = tf.constant("Hello world")
sess = tf.Session()
print(sess.run(hello))

我不斷收到此錯誤:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-f75057d1d95f> in <module>()
----> 1 sess = tf.Session()

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

我知道tf.Session()tensorflow 2.2.0中不受支持,這是我在運行pip install --upgrade tensorflow行后的版本。

我也嘗試過這樣做:

pip install tensorflow==1.4.0

這破壞了環境 tfdeeplearning,我不得不重置環境。

我努力了:

pip uninstall tensorflow-gpu
pip install tensorflow-gpu

這又打破了環境,我不得不再次設置它。

然后我在 jupyter 筆記本中嘗試了這個,它正在替換 import tensorflow as tf:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

這也不起作用,因為這次錯誤說

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

所以,我沒有選擇

PS如果有幫助的話,這是我在虛擬環境中名為 tfdeeplearning 在 conda 中擁有的所有依賴項的列表:

absl-py==0.9.0
appnope==0.1.0
astunparse==1.6.3
bleach==3.1.5
cachetools==4.1.1
certifi==2018.8.24
chardet==3.0.4
cycler==0.10.0
Cython==0.29.21
decorator==4.4.2
defusedxml==0.6.0
entrypoints==0.2.3
gast==0.3.3
google-auth==1.19.2
google-auth-oauthlib==0.4.1
google-pasta==0.2.0
grpcio==1.30.0
h5py==2.10.0
idna==2.10
importlib-metadata==1.7.0
ipykernel==4.10.0
ipython==5.8.0
ipython-genutils==0.2.0
ipywidgets==7.4.1
Jinja2==2.11.2
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.3.3
jupyter-console==5.2.0
jupyter-core==4.5.0
Keras-Preprocessing==1.1.2
kiwisolver==1.0.1
Markdown==3.2.2
MarkupSafe==1.0
matplotlib==3.0.0
mistune==0.8.3
mkl-fft==1.0.6
mkl-random==1.0.1
nbconvert==5.5.0
nbformat==5.0.7
notebook==5.6.0
numpy==1.18.5
oauthlib==3.1.0
opt-einsum==3.3.0
packaging==20.4
pandas==0.22.0
pandocfilters==1.4.2
pexpect==4.6.0
pickleshare==0.7.4
prometheus-client==0.8.0
prompt-toolkit==1.0.15
protobuf==3.12.2
ptyprocess==0.6.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
Pygments==2.6.1
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
pyzmq==17.1.2
qtconsole==4.7.5
QtPy==1.9.0
requests==2.24.0
requests-oauthlib==1.3.0
rsa==4.6
scikit-learn==0.20.0
scipy==1.4.1
Send2Trash==1.5.0
simplegeneric==0.8.1
six==1.15.0
TBB==0.1
tensorboard==2.2.2
tensorboard-plugin-wit==1.7.0
tensorflow==2.2.0
tensorflow-estimator==2.2.0
termcolor==1.1.0
terminado==0.8.1
testpath==0.4.4
tornado==5.1.1
traitlets==4.3.2
urllib3==1.25.10
wcwidth==0.2.5
webencodings==0.5.1
Werkzeug==1.0.1
widgetsnbextension==3.4.1
wrapt==1.12.1
zipp==1.2.0

安裝 Tensorflow 1.15.3。

!pip install tensorflow==1.15.3

import tensorflow as tf
msg = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(msg))

Tensorflow 2.x 默認在 Eager 執行上運行。 不需要通過調用 session 創建圖形。 您仍然可以通過 TF2 中的tf.compat.v1.Session()訪問 session

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM