LoginSignup
8
7

More than 1 year has passed since last update.

PythonにTensorFlowをimportすると「ImportError: DLL load failed: 指定されたモジュールが見つかりません。」と出る

Last updated at Posted at 2020-02-23

環境

  • Windows10
  • Anaconda
  • Python 3.7.4
  • pip 20.0.2

何が起こった

深層学習を試すためTensorFlowをPythonで導入しようと、

pip install tensorflow

と普通にインストール。問題なくインストールが完了。
ここで、きちんとインポートできるかどうか確認すると...

Using TensorFlow backend.
Traceback (most recent call last):
    File "C:...
    ...
    File "C:...
       return _load(spec)
ImportError: DLL load failed: 指定されたモジュールが見つかりません。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    File "C:...
    ...
    File "C:...
       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.

とエラーが出る(長いので途中省略)。

DLLとは汎用性の高い機能をまとめて部品化したプログラムのことで、おおもとのプログラム実行時に動的に(Dynamic)リンクする(Link)ライブラリ(Library)のことである。これが見当たらないぞというよく見かけるエラーなのだが、いろいろ調べ、いろいろやったものの解決せず。

解決策:TensorFlowをダウングレードする

バージョンを指定せずにインストールすると記事作成時点での最新版tensorflow==2.1.0がインストールされるので、プロンプトで以下のように古いバージョンを指定して実行。

pip install --upgrade tensorflow==2.0.0

こうして python コマンドでインタプリタを起動し

>>> import tensorflow

で確認すると問題なくインポートに成功。

バージョンは、

pip install --upgrade tensorflow==

で、吐かれるエラーメッセージ

ERROR: Could not find a version that satisfies the requirement tensorflow== (from versions: ...(ここにインストール可能なバージョンのリストが表示される)...)
ERROR: No matching distribution found for tensorflow==

から問題なくインポートできるバージョンを探した。

経験上とりあえずバージョンを下げるとうまくいくことが多い気がするが、深層学習のライブラリは環境依存が他より顕著なのできちんと公式HPなどを確認してあげたい。

8
7
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
7