본문 바로가기

프로그래밍/AI:ML:DL

[TensorFlow] tensorflow 1.6.0 No module named '_pywrap_tensorflow_internal' 에러

반응형


window 10, 64bit, python 3.6.3 64bit 환경에서 tensorflow (cpu) 를 새롭게 설치하여 import 하였을 때 에러가 발생했다.

에러는 ModuleNotFoundError: No module named '_pywrap_tensorflow_internal' 및 ImportError: DLL load failed: DLL 초기화 루틴을 실행할 수 없습니다.


보통은 이 메시지는 visual c++ 2015 redistributable (64bit) 가 안 깔려있는 경우에 발생하였었다. 하지만, 이번에는 다른 문제였다.

간략히 결론을 말하면, tensorflow cpu 1.6.0 버전에서 문제가 발생했었고, 1.5.0 버전으로 버전을 낮추어 다시 깔아 문제가 해결됐다.


(문제해결 과정 : 문제를 만나고, no module named pywrap_tensorflow_internal error 로 구글검색을 해 보니, tensorflow git 의 issue 링크가 검색되었고, 해당 이슈 토론 쓰레드에서 유사한 문제를 호소하는 사람들이 있었음. 1.6.0 버전에 문제가 있으며 버전 다운그레이드를 권하는 사람의 권고에 따라 버전을 낮추어 깔아보았음.)


추가 : http://daewonyoon.tistory.com/246 동일한 문제에 대한 포스팅이며, 원인에 대한 설명이 추가되어 있음.


아래는 문제와 해결과정까지의 전체 로그이다.


1. keras 를 테스트 해보기 위한 가상환경 생성 및 설정.

D:\WORK\2018>py -3 -m venv envkeras


D:\WORK\2018>envkeras\Scripts\activate

(envkeras) D:\WORK\2018>pip install keras

Collecting keras

  Using cached Keras-2.1.5-py2.py3-none-any.whl

Collecting numpy>=1.9.1 (from keras)

  Using cached numpy-1.14.2-cp36-none-win_amd64.whl

Collecting six>=1.9.0 (from keras)

  Using cached six-1.11.0-py2.py3-none-any.whl

Collecting pyyaml (from keras)

  Downloading PyYAML-3.12.tar.gz (253kB)

    100% |????????????????????????????????| 256kB 936kB/s

Collecting scipy>=0.14 (from keras)

  Using cached scipy-1.0.0-cp36-none-win_amd64.whl

Installing collected packages: numpy, six, pyyaml, scipy, keras

  Running setup.py install for pyyaml ... done

Successfully installed keras-2.1.5 numpy-1.14.2 pyyaml-3.12 scipy-1.0.0 six-1.11.0

You are using pip version 9.0.1, however version 9.0.3 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.


(envkeras) D:\WORK\2018>pip install tensorflow

Collecting tensorflow

  Using cached tensorflow-1.6.0-cp36-cp36m-win_amd64.whl

Collecting gast>=0.2.0 (from tensorflow)

  Using cached gast-0.2.0.tar.gz

Requirement already satisfied: numpy>=1.13.3 in d:\work\2018\envkeras\lib\site-packages (from tensorflow)

Collecting termcolor>=1.1.0 (from tensorflow)

  Using cached termcolor-1.1.0.tar.gz

Collecting absl-py>=0.1.6 (from tensorflow)

  Downloading absl-py-0.1.12.tar.gz (79kB)

    100% |????????????????????????????????| 81kB 856kB/s

Collecting astor>=0.6.0 (from tensorflow)

  Using cached astor-0.6.2-py2.py3-none-any.whl

Requirement already satisfied: six>=1.10.0 in d:\work\2018\envkeras\lib\site-packages (from tensorflow)

Collecting protobuf>=3.4.0 (from tensorflow)

  Using cached protobuf-3.5.2.post1-cp36-cp36m-win_amd64.whl

Collecting tensorboard<1.7.0,>=1.6.0 (from tensorflow)

  Using cached tensorboard-1.6.0-py3-none-any.whl

Collecting grpcio>=1.8.6 (from tensorflow)

  Using cached grpcio-1.10.0-cp36-cp36m-win_amd64.whl

Collecting wheel>=0.26 (from tensorflow)

  Using cached wheel-0.30.0-py2.py3-none-any.whl

Requirement already satisfied: setuptools in d:\work\2018\envkeras\lib\site-packages (from protobuf>=3.4.0->tensorflow)

Collecting html5lib==0.9999999 (from tensorboard<1.7.0,>=1.6.0->tensorflow)

  Using cached html5lib-0.9999999.tar.gz

Collecting werkzeug>=0.11.10 (from tensorboard<1.7.0,>=1.6.0->tensorflow)

  Using cached Werkzeug-0.14.1-py2.py3-none-any.whl

Collecting bleach==1.5.0 (from tensorboard<1.7.0,>=1.6.0->tensorflow)

  Using cached bleach-1.5.0-py2.py3-none-any.whl

Collecting markdown>=2.6.8 (from tensorboard<1.7.0,>=1.6.0->tensorflow)

  Using cached Markdown-2.6.11-py2.py3-none-any.whl

Installing collected packages: gast, termcolor, absl-py, astor, protobuf, html5lib, wheel, werkzeug, bleach, markdown, tensorboard, grpcio, tensorflow

  Running setup.py install for gast ... done

  Running setup.py install for termcolor ... done

  Running setup.py install for absl-py ... done

  Running setup.py install for html5lib ... done

Successfully installed absl-py-0.1.12 astor-0.6.2 bleach-1.5.0 gast-0.2.0 grpcio-1.10.0 html5lib-0.9999999 markdown-2.6.11 protobuf-3.5.2.post1 tensorboard-1.6.0 tensorflow-1.6.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.30.0



2. import 실행 및 에러발생. (+에러로그)

(envkeras) D:\WORK\2018>python

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [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:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper

    return importlib.import_module(mname)

  File "D:\Python3664\lib\importlib\__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked

  File "<frozen importlib._bootstrap>", line 571, in module_from_spec

  File "<frozen importlib._bootstrap_external>", line 922, in create_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

ImportError: DLL load failed: DLL 초기화 루틴을 실행할 수 없습니다.


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>

    from tensorflow.python.pywrap_tensorflow_internal import *

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>

    _pywrap_tensorflow_internal = swig_import_helper()

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper

    return importlib.import_module('_pywrap_tensorflow_internal')

  File "D:\Python3664\lib\importlib\__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

ModuleNotFoundError: 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:\WORK\2018\envkeras\lib\site-packages\keras\__init__.py", line 3, in <module>

    from . import utils

  File "D:\WORK\2018\envkeras\lib\site-packages\keras\utils\__init__.py", line 6, in <module>

    from . import conv_utils

  File "D:\WORK\2018\envkeras\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>

    from .. import backend as K

  File "D:\WORK\2018\envkeras\lib\site-packages\keras\backend\__init__.py", line 84, in <module>

    from .tensorflow_backend import *

  File "D:\WORK\2018\envkeras\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>

    import tensorflow as tf

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\__init__.py", line 24, in <module>

    from tensorflow.python import *

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>

    from tensorflow.python import pywrap_tensorflow

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>

    raise ImportError(msg)

ImportError: Traceback (most recent call last):

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper

    return importlib.import_module(mname)

  File "D:\Python3664\lib\importlib\__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked

  File "<frozen importlib._bootstrap>", line 571, in module_from_spec

  File "<frozen importlib._bootstrap_external>", line 922, in create_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

ImportError: DLL load failed: DLL 초기화 루틴을 실행할 수 없습니다.


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>

    from tensorflow.python.pywrap_tensorflow_internal import *

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>

    _pywrap_tensorflow_internal = swig_import_helper()

  File "D:\WORK\2018\envkeras\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper

    return importlib.import_module('_pywrap_tensorflow_internal')

  File "D:\Python3664\lib\importlib\__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

ModuleNotFoundError: 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.

>>> exit()


3. tensorflow 버전을 확인하고, 강제로 버전번호를 주어 낮은 1.5.0 버전으로 재설치함.

(envkeras) D:\WORK\2018>pip freeze

absl-py==0.1.12

astor==0.6.2

bleach==1.5.0

gast==0.2.0

grpcio==1.10.0

html5lib==0.9999999

Keras==2.1.5

Markdown==2.6.11

numpy==1.14.2

protobuf==3.5.2.post1

PyYAML==3.12

scipy==1.0.0

six==1.11.0

tensorboard==1.6.0

tensorflow==1.6.0

termcolor==1.1.0

Werkzeug==0.14.1


(envkeras) D:\WORK\2018>pip install "tensorflow==1.5"

Collecting tensorflow==1.5

  Using cached tensorflow-1.5.0-cp36-cp36m-win_amd64.whl

Requirement already satisfied: protobuf>=3.4.0 in d:\work\2018\envkeras\lib\site-packages (from tensorflow==1.5)

Requirement already satisfied: wheel>=0.26 in d:\work\2018\envkeras\lib\site-packages (from tensorflow==1.5)

Requirement already satisfied: numpy>=1.12.1 in d:\work\2018\envkeras\lib\site-packages (from tensorflow==1.5)

Requirement already satisfied: six>=1.10.0 in d:\work\2018\envkeras\lib\site-packages (from tensorflow==1.5)

Requirement already satisfied: absl-py>=0.1.6 in d:\work\2018\envkeras\lib\site-packages (from tensorflow==1.5)

Collecting tensorflow-tensorboard<1.6.0,>=1.5.0 (from tensorflow==1.5)

  Using cached tensorflow_tensorboard-1.5.1-py3-none-any.whl

Requirement already satisfied: setuptools in d:\work\2018\envkeras\lib\site-packages (from protobuf>=3.4.0->tensorflow==1.5)

Requirement already satisfied: html5lib==0.9999999 in d:\work\2018\envkeras\lib\site-packages (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5)

Requirement already satisfied: markdown>=2.6.8 in d:\work\2018\envkeras\lib\site-packages (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5)

Requirement already satisfied: bleach==1.5.0 in d:\work\2018\envkeras\lib\site-packages (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5)

Requirement already satisfied: werkzeug>=0.11.10 in d:\work\2018\envkeras\lib\site-packages (from tensorflow-tensorboard<1.6.0,>=1.5.0->tensorflow==1.5)

Installing collected packages: tensorflow-tensorboard, tensorflow

  Found existing installation: tensorflow 1.6.0

    Uninstalling tensorflow-1.6.0:

      Successfully uninstalled tensorflow-1.6.0

Successfully installed tensorflow-1.5.0 tensorflow-tensorboard-1.5.1


4. import 문 실행하여 문제 해결된 것을 확인.

(envkeras) D:\WORK\2018>python

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import keras

Using TensorFlow backend.

>>>



728x90