解決Tensorflow安裝成功,但在導入時報錯的問題
在Mac上按照官網教程安裝成功tensor flow后,但在程序中導入時,仍然報錯,包括但不限于以下兩個錯誤。對于這種錯誤,原因主要在于Mac內默認的python庫比較老了,即便通過pip命令安裝了新的包,python也會默認導入默認位置的包。這時候需要做的就是刪除,有沖突的包,對于以下兩個錯誤,就是分別時numpy和six兩個包沖突了。
可以在python命令行環(huán)境下,通過numpy.version和six.version兩個命令查看當前版本,如果與預期的不一致,就可以刪掉。
可以通過numpy.path查看默認包的位置。
刪掉即可
import tensorflow
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File “”, line 1, in
File “/Library/Python/2.7/site-packages/tensorflow/init.py”, line 24, in
from tensorflow.python import *
File “/Library/Python/2.7/site-packages/tensorflow/python/init.py”, line 49, in
from tensorflow.python import pywrap_tensorflow
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 52, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 41, in
from tensorflow.python.pywrap_tensorflow_internal import *
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
_mod = imp.load_module(‘_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Traceback (most recent call last):
File “”, line 1, in
File “/Library/Python/2.7/site-packages/tensorflow/init.py”, line 24, in
from tensorflow.python import *
File “/Library/Python/2.7/site-packages/tensorflow/python/init.py”, line 104, in
from tensorflow.python.platform import test
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/test.py”, line 41, in
from tensorflow.python.framework import test_util as _test_util
File “/Library/Python/2.7/site-packages/tensorflow/python/framework/test_util.py”, line 54, in
from tensorflow.python.platform import googletest
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/googletest.py”, line 35, in
from tensorflow.python.platform import benchmark
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/benchmark.py”, line 120, in
class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)):
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py”, line 566, in with_metaclass
return meta(“NewBase”, bases, {})
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/benchmark.py”, line 115, in new
if not newclass.is_abstract():
AttributeError: type object ‘NewBase' has no attribute ‘is_abstract'
import tensorflow
Traceback (most recent call last):
File “”, line 1, in
File “/Library/Python/2.7/site-packages/tensorflow/init.py”, line 24, in
from tensorflow.python import *
File “/Library/Python/2.7/site-packages/tensorflow/python/init.py”, line 49, in
from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow
以上這篇解決Tensorflow安裝成功,但在導入時報錯的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
如何解決安裝包過程中的Requirement already satisfied:問題
這篇文章主要介紹了如何解決安裝包過程中的Requirement already satisfied:問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
python中使用 unittest.TestCase單元測試的用例詳解
python 在unittest.TestCase 中提高了很多斷言方法,這篇文章主要介紹了python中使用 unittest.TestCase 進行單元測試的操作方法,需要的朋友可以參考下2021-08-08
關于Pycharm配置翻譯插件Translation報錯更新TTK失敗不能使用的問題
這篇文章主要介紹了關于Pycharm配置翻譯插件Translation報錯更新TTK失敗不能使用的問題,本文通過圖文并茂的形式給大家分享解決方案,需要的朋友可以參考下2022-04-04
Appium+python自動化怎么查看程序所占端口號和IP
這篇文章主要介紹了Appium+python自動化怎么查看程序所占端口號和IP,本文以FQ工具 Lantern 為例,通過圖文并茂的形式給大家介紹的非常詳細,需要的朋友可以參考下2019-06-06

