安裝的tensorflow版本和keras版本可能不合適的時候,會出現(xiàn)報(bào)錯
本文主要介紹Python中,使用tensorflow報(bào)錯:ImportError: cannot import name
'get_config' from 'tensorflow.python.eager.context'
(/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/eager/context.py)解決方法。
參考鏈接:https://www.cjavapy.com/article/2121/
解決方法1:
解決方法2:卸載重新安裝版本之后,不再出現(xiàn)報(bào)錯。
tf_gpu) C:\Users\dell>conda install tensorflow-gpu
Fetching package metadata ...............
Solving package specifications: .
Package plan for installation in environment D:\Users\dell\Anaconda3\envs\tf_gpu:
The following NEW packages will be INSTALLED:
? ? tensorflow:? ? 2.1.0-gpu_py36h3346743_0 defaults
? ? tensorflow-gpu: 2.1.0-h0d30ee6_0? ? ? ? defaults
Proceed ([y]/n)? y
(tf_gpu) C:\Users\dell>conda list -n tf_gpu
# packages in environment at D:\Users\dell\Anaconda3\envs\tf_gpu:
#
_tflow_select? ? ? ? ? ? 2.1.0? ? ? ? ? ? ? ? ? ? ? gpu? ? defaults
absl-py? ? ? ? ? ? ? ? ? 1.0.0? ? ? ? ? ? ? ? ? ? <pip>
absl-py? ? ? ? ? ? ? ? ? 0.15.0? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
aiohttp? ? ? ? ? ? ? ? ? 3.7.4.post0? ? ? py36h2bbff1b_2? ? defaults
astor? ? ? ? ? ? ? ? ? ? 0.8.1? ? ? ? ? ? py36haa95532_0? ? defaults
astor? ? ? ? ? ? ? ? ? ? 0.8.1? ? ? ? ? ? ? ? ? ? <pip>
astunparse? ? ? ? ? ? ? ? 1.6.3? ? ? ? ? ? ? ? ? ? <pip>
async-timeout? ? ? ? ? ? 3.0.1? ? ? ? ? ? py36haa95532_0? ? defaults
attrs? ? ? ? ? ? ? ? ? ? 21.2.0? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
blas? ? ? ? ? ? ? ? ? ? ? 1.0? ? ? ? ? ? ? ? ? ? ? ? mkl? ? defaults
blinker? ? ? ? ? ? ? ? ? 1.4? ? ? ? ? ? ? py36haa95532_0? ? defaults
brotlipy? ? ? ? ? ? ? ? ? 0.7.0? ? ? ? ? py36h2bbff1b_1003? ? defaults
ca-certificates? ? ? ? ? 2021.10.26? ? ? ? ? haa95532_2? ? defaults
cached-property? ? ? ? ? 1.5.2? ? ? ? ? ? ? ? ? ? <pip>
cachetools? ? ? ? ? ? ? ? 4.2.4? ? ? ? ? ? ? ? ? ? <pip>
cachetools? ? ? ? ? ? ? ? 4.2.2? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
certifi? ? ? ? ? ? ? ? ? 2021.10.8? ? ? ? ? ? ? ? <pip>
certifi? ? ? ? ? ? ? ? ? 2021.5.30? ? ? ? py36haa95532_0? ? defaults
cffi? ? ? ? ? ? ? ? ? ? ? 1.14.6? ? ? ? ? py36h2bbff1b_0? ? defaults
chardet? ? ? ? ? ? ? ? ? 4.0.0? ? ? ? ? py36haa95532_1003? ? defaults
charset-normalizer? ? ? ? 2.0.9? ? ? ? ? ? ? ? ? ? <pip>
charset-normalizer? ? ? ? 2.0.4? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
clang? ? ? ? ? ? ? ? ? ? 5.0? ? ? ? ? ? ? ? ? ? ? <pip>
click? ? ? ? ? ? ? ? ? ? 8.0.3? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
coverage? ? ? ? ? ? ? ? ? 5.5? ? ? ? ? ? ? py36h2bbff1b_2? ? defaults
cryptography? ? ? ? ? ? ? 3.4.7? ? ? ? ? ? py36h71e12ea_0? ? defaults
cudatoolkit? ? ? ? ? ? ? 10.1.243? ? ? ? ? ? h74a9793_0? ? defaults
cudnn? ? ? ? ? ? ? ? ? ? 7.6.5? ? ? ? ? ? ? ? cuda10.1_0? ? defaults
cython? ? ? ? ? ? ? ? ? ? 0.29.24? ? ? ? ? py36hd77b12b_0? ? defaults
dataclasses? ? ? ? ? ? ? 0.8? ? ? ? ? ? ? ? ? ? ? <pip>
flatbuffers? ? ? ? ? ? ? 1.12? ? ? ? ? ? ? ? ? ? ? <pip>
gast? ? ? ? ? ? ? ? ? ? ? 0.2.2? ? ? ? ? ? ? ? ? ? <pip>
gast? ? ? ? ? ? ? ? ? ? ? 0.4.0? ? ? ? ? ? ? ? ? ? <pip>
gast? ? ? ? ? ? ? ? ? ? ? 0.2.2? ? ? ? ? ? ? ? ? ? py36_0? ? defaults
google-auth? ? ? ? ? ? ? 1.33.0? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
google-auth? ? ? ? ? ? ? 1.35.0? ? ? ? ? ? ? ? ? ? <pip>
google-auth-oauthlib? ? ? 0.4.6? ? ? ? ? ? ? ? ? ? <pip>
google-auth-oauthlib? ? ? 0.4.4? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
google-pasta? ? ? ? ? ? ? 0.2.0? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
grpcio? ? ? ? ? ? ? ? ? ? 1.43.0? ? ? ? ? ? ? ? ? ? <pip>
grpcio? ? ? ? ? ? ? ? ? ? 1.36.1? ? ? ? ? py36hc60d5dd_1? ? defaults
h5py? ? ? ? ? ? ? ? ? ? ? 2.10.0? ? ? ? ? py36h5e291fa_0? ? defaults
h5py? ? ? ? ? ? ? ? ? ? ? 3.1.0? ? ? ? ? ? ? ? ? ? <pip>
hdf5? ? ? ? ? ? ? ? ? ? ? 1.10.4? ? ? ? ? ? ? h7ebc959_0? ? defaults
icc_rt? ? ? ? ? ? ? ? ? ? 2019.0.0? ? ? ? ? ? h0cc432a_1? ? defaults
idna? ? ? ? ? ? ? ? ? ? ? 3.3? ? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
idna_ssl? ? ? ? ? ? ? ? ? 1.1.0? ? ? ? ? ? py36haa95532_0? ? defaults
importlib-metadata? ? ? ? 4.8.1? ? ? ? ? ? py36haa95532_0? ? defaults
importlib-metadata? ? ? ? 4.8.3? ? ? ? ? ? ? ? ? ? <pip>
intel-openmp? ? ? ? ? ? ? 2021.4.0? ? ? ? ? haa95532_3556? ? defaults
keras? ? ? ? ? ? ? ? ? ? 2.6.0? ? ? ? ? ? ? ? ? ? <pip>
keras-applications? ? ? ? 1.0.8? ? ? ? ? ? ? ? ? ? ? py_1? ? defaults
keras-preprocessing? ? ? 1.1.2? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
libprotobuf? ? ? ? ? ? ? 3.17.2? ? ? ? ? ? ? h23ce68f_1? ? defaults
markdown? ? ? ? ? ? ? ? ? 3.3.4? ? ? ? ? ? py36haa95532_0? ? defaults
Markdown? ? ? ? ? ? ? ? ? 3.3.6? ? ? ? ? ? ? ? ? ? <pip>
mkl? ? ? ? ? ? ? ? ? ? ? 2020.2? ? ? ? ? ? ? ? ? ? ? 256? ? defaults
mkl-service? ? ? ? ? ? ? 2.3.0? ? ? ? ? ? py36h196d8e1_0? ? defaults
mkl_fft? ? ? ? ? ? ? ? ? 1.3.0? ? ? ? ? ? py36h46781fe_0? ? defaults
mkl_random? ? ? ? ? ? ? ? 1.1.1? ? ? ? ? ? py36h47e9c7a_0? ? defaults
multidict? ? ? ? ? ? ? ? 5.1.0? ? ? ? ? ? py36h2bbff1b_2? ? defaults
numpy? ? ? ? ? ? ? ? ? ? 1.19.5? ? ? ? ? ? ? ? ? ? <pip>
numpy? ? ? ? ? ? ? ? ? ? 1.19.2? ? ? ? ? py36hadc3359_0? ? defaults
numpy-base? ? ? ? ? ? ? ? 1.19.2? ? ? ? ? py36ha3acd2a_0? ? defaults
oauthlib? ? ? ? ? ? ? ? ? 3.1.1? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
openssl? ? ? ? ? ? ? ? ? 1.1.1l? ? ? ? ? ? ? h2bbff1b_0? ? defaults
opt_einsum? ? ? ? ? ? ? ? 3.3.0? ? ? ? ? ? ? pyhd3eb1b0_1? ? defaults
pip? ? ? ? ? ? ? ? ? ? ? 21.2.2? ? ? ? ? py36haa95532_0? ? defaults
protobuf? ? ? ? ? ? ? ? ? 3.19.1? ? ? ? ? ? ? ? ? ? <pip>
protobuf? ? ? ? ? ? ? ? ? 3.17.2? ? ? ? ? py36hd77b12b_0? ? defaults
pyasn1? ? ? ? ? ? ? ? ? ? 0.4.8? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
pyasn1-modules? ? ? ? ? ? 0.2.8? ? ? ? ? ? ? ? ? ? <pip>
pyasn1-modules? ? ? ? ? ? 0.2.8? ? ? ? ? ? ? ? ? ? ? py_0? ? defaults
pycparser? ? ? ? ? ? ? ? 2.21? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
pyjwt? ? ? ? ? ? ? ? ? ? 2.1.0? ? ? ? ? ? py36haa95532_0? ? defaults
pyopenssl? ? ? ? ? ? ? ? 21.0.0? ? ? ? ? ? pyhd3eb1b0_1? ? defaults
pyreadline? ? ? ? ? ? ? ? 2.1? ? ? ? ? ? ? ? ? ? ? py36_1? ? defaults
pysocks? ? ? ? ? ? ? ? ? 1.7.1? ? ? ? ? ? py36haa95532_0? ? defaults
python? ? ? ? ? ? ? ? ? ? 3.6.2? ? ? ? ? ? ? h09676a0_15? ? defaults
requests? ? ? ? ? ? ? ? ? 2.27.0? ? ? ? ? ? ? ? ? ? <pip>
requests? ? ? ? ? ? ? ? ? 2.26.0? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
requests-oauthlib? ? ? ? 1.3.0? ? ? ? ? ? ? ? ? ? ? py_0? ? defaults
rsa? ? ? ? ? ? ? ? ? ? ? 4.7.2? ? ? ? ? ? ? pyhd3eb1b0_1? ? defaults
rsa? ? ? ? ? ? ? ? ? ? ? 4.8? ? ? ? ? ? ? ? ? ? ? <pip>
scipy? ? ? ? ? ? ? ? ? ? 1.5.2? ? ? ? ? ? py36h9439919_0? ? defaults
setuptools? ? ? ? ? ? ? ? 58.0.4? ? ? ? ? py36haa95532_0? ? defaults
setuptools? ? ? ? ? ? ? ? 59.6.0? ? ? ? ? ? ? ? ? ? <pip>
six? ? ? ? ? ? ? ? ? ? ? 1.16.0? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
six? ? ? ? ? ? ? ? ? ? ? 1.15.0? ? ? ? ? ? ? ? ? ? <pip>
tensorboard? ? ? ? ? ? ? 2.0.2? ? ? ? ? ? ? ? ? ? <pip>
tensorboard? ? ? ? ? ? ? 2.6.0? ? ? ? ? ? ? ? ? ? <pip>
tensorboard? ? ? ? ? ? ? 2.4.0? ? ? ? ? ? ? pyhc547734_0? ? defaults
tensorboard-data-server? 0.6.1? ? ? ? ? ? ? ? ? ? <pip>
tensorboard-plugin-wit? ? 1.6.0? ? ? ? ? ? ? ? ? ? ? py_0? ? defaults
tensorboard-plugin-wit? ? 1.8.0? ? ? ? ? ? ? ? ? ? <pip>
tensorflow? ? ? ? ? ? ? ? 2.1.0? ? ? ? ? gpu_py36h3346743_0? ? defaults
tensorflow-base? ? ? ? ? 2.1.0? ? ? ? ? gpu_py36h55f5790_0? ? defaults
tensorflow-estimator? ? ? 2.0.1? ? ? ? ? ? ? ? ? ? <pip>
tensorflow-estimator? ? ? 2.6.0? ? ? ? ? ? ? pyh7b7c402_0? ? defaults
tensorflow-gpu? ? ? ? ? ? 2.1.0? ? ? ? ? ? ? ? h0d30ee6_0? ? defaults
termcolor? ? ? ? ? ? ? ? 1.1.0? ? ? ? ? ? ? ? ? ? <pip>
termcolor? ? ? ? ? ? ? ? 1.1.0? ? ? ? ? ? py36haa95532_1? ? defaults
typing-extensions? ? ? ? 3.10.0.2? ? ? ? ? ? hd3eb1b0_0? ? defaults
typing-extensions? ? ? ? 3.7.4.3? ? ? ? ? ? ? ? ? <pip>
typing_extensions? ? ? ? 3.10.0.2? ? ? ? ? pyh06a4308_0? ? defaults
typing_extensions? ? ? ? 4.0.1? ? ? ? ? ? ? ? ? ? <pip>
urllib3? ? ? ? ? ? ? ? ? 1.26.7? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
urllib3? ? ? ? ? ? ? ? ? 1.26.7? ? ? ? ? ? ? ? ? ? <pip>
vc? ? ? ? ? ? ? ? ? ? ? ? 14.2? ? ? ? ? ? ? ? h21ff451_1? ? defaults
vs2015_runtime? ? ? ? ? ? 14.27.29016? ? ? ? ? h5e58377_2? ? defaults
Werkzeug? ? ? ? ? ? ? ? ? 2.0.2? ? ? ? ? ? ? ? ? ? <pip>
werkzeug? ? ? ? ? ? ? ? ? 0.16.1? ? ? ? ? ? ? ? ? ? py_0? ? defaults
wheel? ? ? ? ? ? ? ? ? ? 0.37.0? ? ? ? ? ? pyhd3eb1b0_1? ? defaults
wheel? ? ? ? ? ? ? ? ? ? 0.37.1? ? ? ? ? ? ? ? ? ? <pip>
win_inet_pton? ? ? ? ? ? 1.1.0? ? ? ? ? ? py36haa95532_0? ? defaults
wincertstore? ? ? ? ? ? ? 0.2? ? ? ? ? ? ? py36h7fe50ca_0? ? defaults
wrapt? ? ? ? ? ? ? ? ? ? 1.12.1? ? ? ? ? py36he774522_1? ? defaults
wrapt? ? ? ? ? ? ? ? ? ? 1.13.3? ? ? ? ? ? ? ? ? ? <pip>
yarl? ? ? ? ? ? ? ? ? ? ? 1.6.3? ? ? ? ? ? py36h2bbff1b_0? ? defaults
zipp? ? ? ? ? ? ? ? ? ? ? 3.6.0? ? ? ? ? ? ? pyhd3eb1b0_0? ? defaults
zlib? ? ? ? ? ? ? ? ? ? ? 1.2.11? ? ? ? ? ? ? h8cc25b3_4? ? defaults
(tf_gpu) C:\Users\dell>python
Python 3.6.2 |Anaconda, Inc.| (default, Sep 30 2017, 11:52:29) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> impoer tensorflow
? File "<stdin>", line 1
? ? impoer tensorflow
? ? ? ? ? ? ? ? ? ? ^
SyntaxError: invalid syntax
>>> import tensorflow
>>> import keras
>>>