解决Tensorflow安装成功,但在导入时报错的问题
在Mac上按照官网教程安装成功tensorflow后,但在程序中导入时,仍然报错,包括但不限于以下两个错误。对于这种错误,原因主要在于Mac内默认的python库比较老了,即便通过pip命令安装了新的包,python也会默认导入默认位置的包。这时候需要做的就是删除,有冲突的包,对于以下两个错误,就是分别时numpy和six两个包冲突了。
可以在python命令行环境下,通过numpy.version和six.version两个命令查看当前版本,如果与预期的不一致,就可以删掉。
可以通过numpy.path查看默认包的位置。
删掉即可
importtensorflow
RuntimeError:modulecompiledagainstAPIversion0xabutthisversionofnumpyis0x9 Traceback(mostrecentcalllast): File“”,line1,in File“/Library/Python/2.7/site-packages/tensorflow/init.py”,line24,in fromtensorflow.pythonimport* File“/Library/Python/2.7/site-packages/tensorflow/python/init.py”,line49,in fromtensorflow.pythonimportpywrap_tensorflow File“/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”,line52,in raiseImportError(msg) ImportError:Traceback(mostrecentcalllast): File“/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”,line41,in fromtensorflow.python.pywrap_tensorflow_internalimport* File“/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”,line28,in _pywrap_tensorflow_internal=swig_import_helper() File“/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”,line24,inswig_import_helper _mod=imp.load_module(‘_pywrap_tensorflow_internal',fp,pathname,description) ImportError:numpy.core.multiarrayfailedtoimport FailedtoloadthenativeTensorFlowruntime. Seehttps://www.tensorflow.org/install/install_sources#common_installation_problems forsomecommonreasonsandsolutions.Includetheentirestacktrace abovethiserrormessagewhenaskingforhelp. Traceback(mostrecentcalllast): File“”,line1,in File“/Library/Python/2.7/site-packages/tensorflow/init.py”,line24,in fromtensorflow.pythonimport* File“/Library/Python/2.7/site-packages/tensorflow/python/init.py”,line104,in fromtensorflow.python.platformimporttest File“/Library/Python/2.7/site-packages/tensorflow/python/platform/test.py”,line41,in fromtensorflow.python.frameworkimporttest_utilas_test_util File“/Library/Python/2.7/site-packages/tensorflow/python/framework/test_util.py”,line54,in fromtensorflow.python.platformimportgoogletest File“/Library/Python/2.7/site-packages/tensorflow/python/platform/googletest.py”,line35,in fromtensorflow.python.platformimportbenchmark File“/Library/Python/2.7/site-packages/tensorflow/python/platform/benchmark.py”,line120,in classBenchmark(six.with_metaclass(_BenchmarkRegistrar,object)): File“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py”,line566,inwith_metaclass returnmeta(“NewBase”,bases,{}) File“/Library/Python/2.7/site-packages/tensorflow/python/platform/benchmark.py”,line115,innew ifnotnewclass.is_abstract(): AttributeError:typeobject‘NewBase'hasnoattribute‘is_abstract' importtensorflow Traceback(mostrecentcalllast): File“”,line1,in File“/Library/Python/2.7/site-packages/tensorflow/init.py”,line24,in fromtensorflow.pythonimport* File“/Library/Python/2.7/site-packages/tensorflow/python/init.py”,line49,in fromtensorflow.pythonimportpywrap_tensorflow ImportError:cannotimportnamepywrap_tensorflow
以上这篇解决Tensorflow安装成功,但在导入时报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。