Python3.5 win10環(huán)境下導入kera/tensorflow報錯的解決方法
本文實例講述了Python3.5 win10環(huán)境下導入keras/tensorflow報錯的解決方法。分享給大家供大家參考,具體如下:
我在win10 Python3.5.2安裝keras,然后導入時報錯如下:
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import keras Using TensorFlow backend. Traceback (most recent call last): File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper return importlib.import_module(mname) File "d:\Anaconda3\envs\tf\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 666, in _load_unlocked File "<frozen importlib._bootstrap>", line 577, in module_from_spec File "<frozen importlib._bootstrap_external>", line 906, in create_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed ImportError: DLL load failed: The specified module could not be found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper return importlib.import_module('_pywrap_tensorflow_internal') File "d:\Anaconda3\envs\tf\lib\importlib\__init__.py", line 126, in import_module return _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 "<stdin>", line 1, in <module> File "d:\Anaconda3\envs\tf\lib\site-packages\keras\__init__.py", line 3, in <module> from . import activations File "d:\Anaconda3\envs\tf\lib\site-packages\keras\activations.py", line 4, in <module> from . import backend as K File "d:\Anaconda3\envs\tf\lib\site-packages\keras\backend\__init__.py", line 73, in <module> from .tensorflow_backend import * File "d:\Anaconda3\envs\tf\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in <module> import tensorflow as tf File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 24, in <module> from tensorflow.python import * File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\__init__.py", line 51, in <module> from tensorflow.python import pywrap_tensorflow File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module> raise ImportError(msg) ImportError: Traceback (most recent call last): File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper return importlib.import_module(mname) File "d:\Anaconda3\envs\tf\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 666, in _load_unlocked File "<frozen importlib._bootstrap>", line 577, in module_from_spec File "<frozen importlib._bootstrap_external>", line 906, in create_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed ImportError: DLL load failed: The specified module could not be found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper return importlib.import_module('_pywrap_tensorflow_internal') File "d:\Anaconda3\envs\tf\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named '_pywrap_tensorflow_internal' 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.
又臭又長的問題說導入keras時先導入TensorFlow,然后出現(xiàn)導入失敗,解決方法有兩個:
一.安裝Microsoft Visual C++ 2015 Redistributable Update 3
先在https://www.microsoft.com/en-us/download/details.aspx?id=53587
下載Microsoft Visual C++ 2015 Redistributable Update 3。
然后安裝。
接下來重啟電腦,然后卸載tensorflow:
pip uninstall tensorflow pip uninstall tensorflow-gpu
然后再重裝:
pip install tensorflow pip install tensorflow-gpu
再重新導入應該不會報錯了。
如果無法解決,看下面的方法:
二.cmd下敲命令:
pip install --upgrade --ignore-installed setuptools
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python數(shù)學運算技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進階經(jīng)典教程》
希望本文所述對大家Python程序設計有所幫助。
相關(guān)文章
用Python編寫生成樹狀結(jié)構(gòu)的文件目錄的腳本的教程
這篇文章主要介紹了用Python編寫生成樹狀結(jié)構(gòu)的文件目錄的腳本的教程,是一個利用os模塊下各函數(shù)的簡單實現(xiàn),需要的朋友可以參考下2015-05-05一篇文章教你掌握python數(shù)據(jù)類型的底層實現(xiàn)
這篇文章主要介紹了Python 數(shù)據(jù)類型的底層實現(xiàn)原理分析,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-09-09