1. 程式人生 > >mport tensorflowwwwhj6666com時會出現如下錯誤13094399995

mport tensorflowwwwhj6666com時會出現如下錯誤13094399995

Windows Server安裝tensorflow後ImportError錯誤完美解決
原創 資料觀世界 2018-11-24 22:42:29
Windows Server安裝tensorflow後ImportError錯誤完美解決
資料觀世界
近期由於學術需要,需要在伺服器上跑深度神經網路,我們的網路程式碼是基於tensorflow的,所以首要的就是要在伺服器上安裝Python和tensorflow。

我們的環境是:

tensorflow 1.12.0
所有的一切都很順利,包括tensorflow的安裝(pip install tensorflow),但在執行程式碼時或者在python命令列下執行import tensorflow時,會出現如下錯誤:

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow.py”, l ine 41, infrom tensorflow.python.pywrap_tensorflow_internal import *

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow_intern al.py”, line 21, in_pywrap_tensorflow_internal = swig_import_helper()

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow_intern al.py”, line 20, in swig_import_helperreturn importlib.import_module(‘pywrap_tensorflow_internal’)

File “D:Python35libimportlib_init.py”, line 126, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named ‘_pywrap_tensorflow_internal’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “ “, line 1, inFile “D:Python35libsite-packages ensorflowinit.py”, line 24, infrom tensorflow.python import *

File “D:Python35libsite-packages ensorflowpythoninit.py”, line 51, i nfrom tensorflow.python import pywraptensorflow

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow.py”, l ine 52, inraise ImportError(msg) ImportError: Traceback (most recent call last):

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow_intern al.py”, line 18, in swig_import_helperreturn importlib.import_module(mname)

File “D:Python35libimportlib_init.py”, line 126, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)

File “ “, line 986, in _gcd_import File “ “, line 969, in _find_and_load File “ “, line 958, in _find_and_load_unlocked

File “ “, line 666, in _load_unlocked

File “ “, line 577, in module_from_spec

File “ “, line 906, in create_module File “ “, line 222, in _call_with_frames_removed ImportError: DLL load failed: 找不到指定的模組。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow.py”, l ine 41, infrom tensorflow.python.pywrap_tensorflow_internal import *

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow_intern al.py”, line 21, in_pywrap_tensorflow_internal = swig_import_helper()

File “D:Python35libsite-packages ensorflowpythonpywrap_tensorflow_intern al.py”, line 20, in swig_import_helperreturn importlib.import_module(‘pywrap_tensorflow_internal’)

File “D:Python35libimportlib_init.py”, line 126, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)

ImportError: No module named ‘_pywrap_tensorflow_internal’

Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_st arted/os_setup.md#import_errorfor some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

您遇到的錯誤可能不完全一樣,但是如果在使用時出現類似的DLL load failed 或者 ImportError錯誤提示,本文都可以為您提供參考。

為了解決這個問題,我浪費了大量的時間。這個過程中我感覺內心是極其煎熬的,明知道是一個很小的錯誤,卻不知道該怎麼解決。而且發現網上相關的問題搜尋結果極少,所以發此文,希望為大家提供到幫助。

Windows Server安裝tensorflow後ImportError錯誤完美解決
最後我找到的解決辦法,就是安裝C++ 2015 Redistributable Update 3。您可以從這裡下載:https://www.microsoft.com/en-us/download/details.aspx?id=53587,按照提示下載安裝之後,在python命令列下import tensorflow的錯誤就完全消失了,執行深度神經網路程式碼檔案也再沒出現過問題。

通過此方法完美解決,也許這是我的個例。如果你通過上面這個方法沒有完全解決問題,請參考下面的方法:

從https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c,下載檔案:tensorflow_self_check.py,在本地執行此檔案,便可自動檢測您的執行環境存在的詳細問題。

該檔案執行結果可能會反饋給您多條待解決的問題,根據個人經歷,我建議您從第一條開始,解決一條問題之後,然後用import tensorflow測驗,如果仍出現報錯,則繼續解決下一條問題,以此類推。避免進行不必要的下載與安裝。

以上就是今天分享的所有內容,希望能幫到您,也祝願大家執行程式碼時一切順利!