解決Tensorflow安裝成功,但在導(dǎo)入時報錯的問題
在Mac上按照官網(wǎng)教程安裝成功tensor flow后,但在程序中導(dǎo)入時,仍然報錯,包括但不限于以下兩個錯誤。對于這種錯誤,原因主要在于Mac內(nèi)默認的python庫比較老了,即便通過pip命令安裝了新的包,python也會默認導(dǎo)入默認位置的包。這時候需要做的就是刪除,有沖突的包,對于以下兩個錯誤,就是分別時numpy和six兩個包沖突了。
可以在python命令行環(huán)境下,通過numpy.version和six.version兩個命令查看當(dāng)前版本,如果與預(yù)期的不一致,就可以刪掉。
可以通過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安裝成功,但在導(dǎo)入時報錯的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python切換pip源兩種方法(解決pip?install慢)
這篇文章主要給大家介紹了關(guān)于Python切換pip源兩種方法(解決pip?install慢),我總結(jié)的這幾種更換pip源的常用方式,希望可以幫助您成功配置國內(nèi)源,解決安裝Python包速度慢的問題,需要的朋友可以參考下2023-11-11
淺析python 內(nèi)置字符串處理函數(shù)的使用方法
這篇文章主要介紹了python 內(nèi)置字符串處理函數(shù)的使用方法,需要的朋友可以參考下2014-06-06
Tensorflow實現(xiàn)神經(jīng)網(wǎng)絡(luò)擬合線性回歸
這篇文章主要為大家詳細介紹了Tensorflow實現(xiàn)神經(jīng)網(wǎng)絡(luò)擬合線性回歸,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07
Python異常處理與反射相關(guān)問題總結(jié)
今天給大家?guī)淼氖顷P(guān)于Python的相關(guān)知識,文章圍繞著Python異常處理與反射展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下2021-06-06
Python?Pytorch學(xué)習(xí)之圖像檢索實踐
隨著電子商務(wù)和在線網(wǎng)站的出現(xiàn),圖像檢索在我們的日常生活中的應(yīng)用一直在增加。圖像檢索的基本本質(zhì)是根據(jù)查詢圖像的特征從集合或數(shù)據(jù)庫中查找圖像。本文將利用Pytorch實現(xiàn)圖像檢索,需要的可以參考一下2022-04-04
Python3數(shù)據(jù)庫操作包pymysql的操作方法
這篇文章主要介紹了Python3數(shù)據(jù)庫操作包pymysql的操作方法,文章通過實例代碼相結(jié)合給大家介紹的非常詳細,需要的朋友可以參考下2018-07-07
Python使用PyPDF2和ReportLab操作PDF文件的詳細指南
在日常工作和項目中,PDF 文件處理是個常見需求,不論是合并報告、加密文檔、填充表單,還是生成發(fā)票,Python 中有許多用于操作 PDF 文件的庫,其中 PyPDF2 和 ReportLab 是兩個廣泛使用的工具,本文給大家介紹了Python使用PyPDF2和ReportLab操作PDF文件的詳細指南2025-01-01
Python連接SQLite數(shù)據(jù)庫操作實戰(zhàn)指南從入門到精通
在Python中使用SQLite進行數(shù)據(jù)庫操作時,我們將深入研究SQLite數(shù)據(jù)庫的創(chuàng)建、表格管理、數(shù)據(jù)插入、查詢、更新和刪除等關(guān)鍵主題,幫助你全面了解如何使用SQLite進行數(shù)據(jù)庫操作2023-11-11

