Tensorflow のインストールがうまくいかないときの対処


Tensorflow のインストールがうまくいかないときの対処

Tensorflow のインストール

Tensorflow のインストールは、「pip での TensorFlow のインストール」に記載されている手順のとおりやれば問題なく行える。
ちなみに、私はAnaconda を使わずに、Python と PyCharm だけで環境構築している。

うまくいかないときのパターン

Python のバージョンと Tensorflow のバージョンが適合していないと、エラーメッセージが表示され、プログラムが正しく動作しないことがある。

現在、Python 3.7.7 を使用しているが、Tensorflow 2.2.0 をインストールしたときは、プログラム実行に Warning や Error が表示された。

対応方法

Tensorflow 2.1.0 にダウングレードすると、 Warning や Error は表示されなくなった。

Tensorflow のバージョンを変えてみるとうまくいくことがある。

以下は、Tensorflow のインストールの検証結果である。

検証コマンド

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
view raw gistfile1.txt hosted with ❤ by GitHub

Tensorflow 2.2.0 をインストールしたときの検証結果

(venv) C:\Development\Python\Project001>python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
Traceback (most recent call last):
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Development\Python\Project001\venv\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\sufbl\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\sufbl\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, 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 "<string>", line 1, in <module>
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Development\Python\Project001\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Development\Python\Project001\venv\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\sufbl\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\sufbl\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, 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.

Tensorflow 2.1.0 をインストールしたときの検証結果

(venv) C:\Development\Python\Project001>python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2020-05-27 01:08:03.119495: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
tf.Tensor(491.3349, shape=(), dtype=float32)




Posted in  on 5/27/2020 by rteak |