安装的tensorflow版本和keras版本可能不合适的时候,会出现报错
本文主要介绍Python中,使用tensorflow报错: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:卸载重新安装版本之后,不再出现报错。
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
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
astunparse 1.6.3
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
cachetools 4.2.4
cachetools 4.2.2 pyhd3eb1b0_0 defaults
certifi 2021.10.8
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
charset-normalizer 2.0.4 pyhd3eb1b0_0 defaults
clang 5.0
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
flatbuffers 1.12
gast 0.2.2
gast 0.4.0
gast 0.2.2 py36_0 defaults
google-auth 1.33.0 pyhd3eb1b0_0 defaults
google-auth 1.35.0
google-auth-oauthlib 0.4.6
google-auth-oauthlib 0.4.4 pyhd3eb1b0_0 defaults
google-pasta 0.2.0 pyhd3eb1b0_0 defaults
grpcio 1.43.0
grpcio 1.36.1 py36hc60d5dd_1 defaults
h5py 2.10.0 py36h5e291fa_0 defaults
h5py 3.1.0
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
intel-openmp 2021.4.0 haa95532_3556 defaults
keras 2.6.0
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
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
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
protobuf 3.17.2 py36hd77b12b_0 defaults
pyasn1 0.4.8 pyhd3eb1b0_0 defaults
pyasn1-modules 0.2.8
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
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
scipy 1.5.2 py36h9439919_0 defaults
setuptools 58.0.4 py36haa95532_0 defaults
setuptools 59.6.0
six 1.16.0 pyhd3eb1b0_0 defaults
six 1.15.0
tensorboard 2.0.2
tensorboard 2.6.0
tensorboard 2.4.0 pyhc547734_0 defaults
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.6.0 py_0 defaults
tensorboard-plugin-wit 1.8.0
tensorflow 2.1.0 gpu_py36h3346743_0 defaults
tensorflow-base 2.1.0 gpu_py36h55f5790_0 defaults
tensorflow-estimator 2.0.1
tensorflow-estimator 2.6.0 pyh7b7c402_0 defaults
tensorflow-gpu 2.1.0 h0d30ee6_0 defaults
termcolor 1.1.0
termcolor 1.1.0 py36haa95532_1 defaults
typing-extensions 3.10.0.2 hd3eb1b0_0 defaults
typing-extensions 3.7.4.3
typing_extensions 3.10.0.2 pyh06a4308_0 defaults
typing_extensions 4.0.1
urllib3 1.26.7 pyhd3eb1b0_0 defaults
urllib3 1.26.7
vc 14.2 h21ff451_1 defaults
vs2015_runtime 14.27.29016 h5e58377_2 defaults
Werkzeug 2.0.2
werkzeug 0.16.1 py_0 defaults
wheel 0.37.0 pyhd3eb1b0_1 defaults
wheel 0.37.1
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
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 "
impoer tensorflow
^
SyntaxError: invalid syntax
>>> import tensorflow
>>> import keras
>>>