近期由于学术需要,需要在服务器上跑深度神经网络,我们的网络代码是基于tensorflow的,所以首要的就是要在服务器上安装Python和tensorflow。
我们的环境是:
windows server 2008 r1(x64)
Python 3.6.5
tensorflow 1.12.0
所有的一切都很顺利,包括tensorflow的安装(pip install tensorflow),但在运行代码时或者在python命令行下运行import tensorflow时,会出现如下错误:
During handling of the above exception, another exception occurred:Traceback (most recent call last):File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line41,infromtensorflow.python.pywrap_tensorflow_internalimport*File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line21,in_pywrap_tensorflow_internal = swig_import_helper()File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line20,inswig_import_helperreturnimportlib.import_module(‘pywrap_tensorflow_internal’)File “D:\Python35\lib\importlib_init.py”, line126,inimport_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 “ “, line1,inFile “D:\Python35\lib\site-packages\tensorflowinit.py”, line24,infromtensorflow.pythonimport*File “D:\Python35\lib\site-packages\tensorflow\pythoninit.py”, line51, infromtensorflow.pythonimportpywraptensorflowFile “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line52,inraiseImportError(msg)ImportError: Traceback (most recent call last):File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line18,inswig_import_helperreturnimportlib.import_module(mname)File “D:\Python35\lib\importlib_init.py”, line126,inimport_modulereturn_bootstrap._gcd_import(name[level:], package, level)File “ “, line986,in_gcd_importFile “ “, line969,in_find_and_loadFile “ “, line958,in_find_and_load_unlockedFile “ “, line666,in_load_unlockedFile “ “, line577,inmodule_from_specFile “ “, line906,increate_moduleFile “ “, line222,in_call_with_frames_removedImportError: DLL load failed: 找不到指定的模块。During handling of the above exception, another exception occurred:Traceback (most recent call last):File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line41,infromtensorflow.python.pywrap_tensorflow_internalimport*File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line21,in_pywrap_tensorflow_internal = swig_import_helper()File “D:\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line20,inswig_import_helperreturnimportlib.import_module(‘pywrap_tensorflow_internal’)File “D:\Python35\lib\importlib_init.py”, line126,inimport_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_started/os_setup.md#import_errorforsome common reasonsandsolutions. Include the entire stack traceabove this error message when askingforhelp.
您遇到的错误可能不完全一样,但是如果在使用时出现类似的DLL load failed 或者 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测验,如果仍出现报错,则继续解决下一条问题,以此类推。避免进行不必要的下载与安装。
以上就是今天分享的所有内容,希望能帮到您,也祝愿大家运行代码时一切顺利!
END
本公众号原创作品,未经授权禁止转载,特此声明,谢谢合作!