LoginSignup
8
11

More than 3 years have passed since last update.

[環境構築]TensorFlow動かすと「ImportError: DLL load failed:~」が出る

Posted at

背景

Interface 2019年5月号(CQ出版)の記事の中に、Tensorflow Object Detection APIを使用した物体検知についてのサンプルがあり、面白そうなので動かしてみたいと思いました。しかし、環境構築でかなり躓いてしまったので記録を残しておきます。

環境

  • windows 10
  • python=3.6.5

やったこと

まずは雑誌の記事を参考に環境構築をしましたが、エラーが出てうまくいきませんでした。そこで、以下の記事を参考に改めて環境構築をしました。

Anaconda PromptでのTensorFlowの導入に苦戦した話
TensorFlow Object Detection APIをWindowsで使ってみた

しかし、うまくいかず、tensorflowをimportしようとすると、以下のようなエラーがでてきました。

Traceback (most recent call last):
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Users\grin\Anaconda3\envs\study\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\grin\Anaconda3\envs\study\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 指定されたモジュールが見つかりません。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "detect_cat.py", line 2, in <module>
    import tensorflow as tf
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\grin\Anaconda3\envs\study\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Users\grin\Anaconda3\envs\study\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\grin\Anaconda3\envs\study\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 指定されたモジュールが見つかりません。


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
exit status 1

そこからは、「何かわからんがくらえッ!」精神で、ここここなんかを参考に、地獄のようにpip install ~, pip uninstall ~, conda install ~, conda uninstall ~, ... を繰り返しました。
結果・・・

こうすればできました

新しく環境を作ります。
$conda create -n test python=3.6.5 anaconda

環境をactivateしたら、

$pip install tensorflow==1.12.0
これだけでした。。。

tensorflowのバージョンを指定しないと、私の環境だとデフォルトで1.13.1がインストールされ、これがどうも相性が悪いみたいでした。

物体検知のサンプルも無事、実行できました。

output.jpg
画像出典(https://www.pakutaso.com/20190201044post-19435.html)

「何かわからんがクラ・・・」
いや、、tie...ネクタイ?person...人??
まあ、ネクタイした人にも見え・・・ないですね

8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11