在导入tensorflow和keras库时出现错误



导入tensorflow为tf导入keras都显示相同的错误

"name": "ImportError",
"message": "Traceback (most recent call last):n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>n    from tensorflow.python.pywrap_tensorflow_internal import *n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>n    _pywrap_tensorflow_internal = swig_import_helper()n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helpern    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imp.py", line 243, in load_modulen    return load_dynamic(name, filename, file)n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imp.py", line 343, in load_dynamicn    return _load(spec)nImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 0x0006): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))nnnFailed to load the native TensorFlow runtime.nnSee https://www.tensorflow.org/install/errorsnnfor some common reasons and solutions.  Include the entire stack tracenabove this error message when asking for help.",
"stack": "u001b[0;31m---------------------------------------------------------------------------u001b[0mnu001b[0;31mImportErroru001b[0m                               Traceback (most recent call last)nFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow.py:58u001b[0mnu001b[1;32m     56u001b[0m   sysu001b[39m.u001b[39msetdlopenflags(_default_dlopen_flags u001b[39m|u001b[39m ctypesu001b[39m.u001b[39mRTLD_LOCAL)nu001b[0;32m---> 58u001b[0m u001b[39mfromu001b[39;00m u001b[39mtensorflowu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpythonu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpywrap_tensorflow_internalu001b[39;00m u001b[39mimportu001b[39;00m u001b[39m*u001b[39mnu001b[1;32m     59u001b[0m u001b[39mfromu001b[39;00m u001b[39mtensorflowu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpythonu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpywrap_tensorflow_internalu001b[39;00m u001b[39mimportu001b[39;00m __version__nnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:28u001b[0mnu001b[1;32m     27u001b[0m         u001b[39mreturnu001b[39;00m _modnu001b[0;32m---> 28u001b[0m _pywrap_tensorflow_internal u001b[39m=u001b[39m swig_import_helper()nu001b[1;32m     29u001b[0m u001b[39mdelu001b[39;00m swig_import_helpernnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:24u001b[0m, in u001b[0;36mswig_import_helperu001b[0;34m()u001b[0mnu001b[1;32m     23u001b[0m u001b[39mtryu001b[39;00m:nu001b[0;32m---> 24u001b[0m     _mod u001b[39m=u001b[39m impu001b[39m.u001b[39;49mload_module(u001b[39m'u001b[39;49mu001b[39m_pywrap_tensorflow_internalu001b[39;49mu001b[39m'u001b[39;49m, fp, pathname, description)nu001b[1;32m     25u001b[0m u001b[39mfinallyu001b[39;00m:nnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imp.py:243u001b[0m, in u001b[0;36mload_moduleu001b[0;34m(name, file, filename, details)u001b[0mnu001b[1;32m    242u001b[0m     u001b[39melseu001b[39;00m:nu001b[0;32m--> 243u001b[0m         u001b[39mreturnu001b[39;00m load_dynamic(name, filename, file)nu001b[1;32m    244u001b[0m u001b[39melifu001b[39;00m type_ u001b[39m==u001b[39m PKG_DIRECTORY:nnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imp.py:343u001b[0m, in u001b[0;36mload_dynamicu001b[0;34m(name, path, file)u001b[0mnu001b[1;32m    341u001b[0m spec u001b[39m=u001b[39m importlibu001b[39m.u001b[39mmachineryu001b[39m.u001b[39mModuleSpec(nu001b[1;32m    342u001b[0m     nameu001b[39m=u001b[39mname, loaderu001b[39m=u001b[39mloader, originu001b[39m=u001b[39mpath)nu001b[0;32m--> 343u001b[0m u001b[39mreturnu001b[39;00m _load(spec)nnu001b[0;31mImportErroru001b[0m: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 0x0006): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))nnDuring handling of the above exception, another exception occurred:nnu001b[0;31mImportErroru001b[0m                               Traceback (most recent call last)nCell u001b[0;32mIn [14], line 1u001b[0mnu001b[0;32m----> 1u001b[0m u001b[38;5;28;01mimportu001b[39;00m u001b[38;5;21;01mtensorflowu001b[39;00m u001b[38;5;28;01masu001b[39;00m u001b[38;5;21;01mtfu001b[39;00mnnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/__init__.py:24u001b[0mnu001b[1;32m     21u001b[0m u001b[39mimportu001b[39;00m u001b[39mosu001b[39;00m u001b[39masu001b[39;00m u001b[39m_osu001b[39;00mnu001b[1;32m     23u001b[0m u001b[39m# pylint: disable=g-bad-import-orderu001b[39;00mnu001b[0;32m---> 24u001b[0m u001b[39mfromu001b[39;00m u001b[39mtensorflowu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpythonu001b[39;00m u001b[39mimportu001b[39;00m pywrap_tensorflow  u001b[39m# pylint: disable=unused-importu001b[39;00mnu001b[1;32m     26u001b[0m u001b[39mtryu001b[39;00m:nu001b[1;32m     27u001b[0m   u001b[39m# Add `estimator` attribute to allow access to estimator APIs viau001b[39;00mnu001b[1;32m     28u001b[0m   u001b[39m# "tf.estimator..."u001b[39;00mnu001b[1;32m     29u001b[0m   u001b[39mfromu001b[39;00m u001b[39mtensorflowu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpythonu001b[39;00mu001b[39m.u001b[39;00mu001b[39mestimatoru001b[39;00mu001b[39m.u001b[39;00mu001b[39mapiu001b[39;00m u001b[39mimportu001b[39;00m estimator  u001b[39m# pylint: disable=g-import-not-at-topu001b[39;00mnnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/__init__.py:49u001b[0mnu001b[1;32m     32u001b[0m u001b[39m# TODO(drpng): write up instructions for editing this file in a doc and point tou001b[39;00mnu001b[1;32m     33u001b[0m u001b[39m# the doc instead.u001b[39;00mnu001b[1;32m     34u001b[0m u001b[39m# If you want to edit this file to expose modules in public tensorflow API, youu001b[39;00mnu001b[0;32m   (...)u001b[0mnu001b[1;32m     44u001b[0m u001b[39m# go/tf-wildcard-importu001b[39;00mnu001b[1;32m     45u001b[0m u001b[39m# pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-topu001b[39;00mnu001b[1;32m     47u001b[0m u001b[39mimportu001b[39;00m u001b[39mnumpyu001b[39;00m u001b[39masu001b[39;00m u001b[39mnpu001b[39;00mnu001b[0;32m---> 49u001b[0m u001b[39mfromu001b[39;00m u001b[39mtensorflowu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpythonu001b[39;00m u001b[39mimportu001b[39;00m pywrap_tensorflownu001b[1;32m     51u001b[0m u001b[39mfromu001b[39;00m u001b[39mtensorflowu001b[39;00mu001b[39m.u001b[39;00mu001b[39mpythonu001b[39;00mu001b[39m.u001b[39;00mu001b[39mtoolsu001b[39;00m u001b[39mimportu001b[39;00m component_api_helpernu001b[1;32m     52u001b[0m component_api_helperu001b[39m.u001b[39mpackage_hook(nu001b[1;32m     53u001b[0m     parent_package_stru001b[39m=u001b[39mu001b[39m'u001b[39mu001b[39mtensorflow.pythonu001b[39mu001b[39m'u001b[39m,nu001b[1;32m     54u001b[0m     child_package_stru001b[39m=u001b[39m(nu001b[1;32m     55u001b[0m         u001b[39m'u001b[39mu001b[39mtensorflow_estimator.python.estimatoru001b[39mu001b[39m'u001b[39m))nnFile u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow.py:74u001b[0mnu001b[1;32m     69u001b[0m u001b[39mexceptu001b[39;00m u001b[39mImportErroru001b[39;00m:nu001b[1;32m     70u001b[0m   msg u001b[39m=u001b[39m u001b[39m"""u001b[39mu001b[39m%su001b[39;00mu001b[39m\nu001b[39;00mu001b[39m\nu001b[39;00mu001b[39mFailed to load the native TensorFlow runtime.u001b[39mu001b[39m\nu001b[39;00mnu001b[1;32m     71u001b[0m u001b[39mSee https://www.tensorflow.org/install/errorsu001b[39mu001b[39m\nu001b[39;00mnu001b[1;32m     72u001b[0m u001b[39mfor some common reasons and solutions.  Include the entire stack traceu001b[39mnu001b[1;32m     73u001b[0m u001b[39mabove this error message when asking for help.u001b[39mu001b[39m"""u001b[39m u001b[39m%u001b[39m tracebacku001b[39m.u001b[39mformat_exc()nu001b[0;32m---> 74u001b[0m   u001b[39mraiseu001b[39;00m u001b[39mImportErroru001b[39;00m(msg)nnu001b[0;31mImportErroru001b[0m: Traceback (most recent call last):n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>n    from tensorflow.python.pywrap_tensorflow_internal import *n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>n    _pywrap_tensorflow_internal = swig_import_helper()n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helpern    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imp.py", line 243, in load_modulen    return load_dynamic(name, filename, file)n  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imp.py", line 343, in load_dynamicn    return _load(spec)nImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 0x0006): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))nnnFailed to load the native TensorFlow runtime.nnSee https://www.tensorflow.org/install/errorsnnfor some common reasons and solutions.  Include the entire stack tracenabove this error message when asking for help."

我尝试导入tensorflow和keras库,但我得到这个错误无处不在。

您的系统似乎没有正确安装Tensorflow。请按照以下步骤在您的系统中安装Tensorflow

# Requires the latest pip
pip install --upgrade pip
# Current stable release for CPU and GPU
pip install tensorflow
# Check the installed tensorflow version
import tensorflow as tf
tf.__version__

或者您可以按照本链接中提到的step by step instructions使用Conda环境通过检查硬件和软件要求来安装TensorFlow

您需要安装python-dev:

sudo apt install python-dev

之后还可以安装grpcio

相关内容

  • 没有找到相关文章