長い長い Tensorflow のビルドを終えて、最後にちゃんとビルドできている確かめるために、
import tensorflow as tf
とするのだけど、下記の用なエラーが出力されて、ものすごくがっかりする。
$ python3
Python 3.6.3 (default, Dec 15 2017, 16:04:49)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "/opt/tensorflow/v1.8.0/tensorflow/python/platform/self_check.py", line 25, in <module>
from tensorflow.python.platform import build_info
ImportError: cannot import name 'build_info'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/tensorflow/v1.8.0/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/opt/tensorflow/v1.8.0/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/opt/tensorflow/v1.8.0/tensorflow/python/pywrap_tensorflow.py", line 25, in <module>
from tensorflow.python.platform import self_check
File "/opt/tensorflow/v1.8.0/tensorflow/python/platform/self_check.py", line 27, in <module>
raise ImportError("Could not import tensorflow. Do not import tensorflow "
ImportError: Could not import tensorflow. Do not import tensorflow from its source directory; change directory to outside the TensorFlow source tree, and relaunch your Python interpreter from there.
>>>
けど、ちゃんとインストール手順( https://www.tensorflow.org/install/install_sources#ConfigureInstallation )を読めば、なんのことはない
Change directory (cd) to any directory on your system other than the tensorflow subdirectory from which you invoked the configure command.
と、ビルドしたディレクトリから出ろ、と書いてある。
どこか別のディレクトリで実行するとエラーが出ず、ここでやっと笑顔になれる。
$ python3
Python 3.6.3 (default, Dec 15 2017, 16:04:49)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2018-05-18 16:31:29.459699: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-05-18 16:31:29.460207: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties:
name: GeForce GTX 1070 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:01:00.0
totalMemory: 7.93GiB freeMemory: 7.48GiB
2018-05-18 16:31:29.460251: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-05-18 16:31:29.618045: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-05-18 16:31:29.618077: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0
2018-05-18 16:31:29.618086: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N
2018-05-18 16:31:29.618238: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7229 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>