美文网首页我爱编程
安装TensorFlow步骤及要点

安装TensorFlow步骤及要点

作者: 盗花 | 来源:发表于2017-02-11 10:45 被阅读4824次

TensorFlow是谷歌打造的一款机器学习框架,最近很火。现在把本地机及远程机的安装过程记录如下:

本地机安装

我的本地机器是MacOs,已经预先装好了HomeBrewPIP等安装包,安装时的参考网址为:https://www.tensorflow.org/get_started/os_setup
网上有一个中文版的安装网址:http://www.tensorfly.cn/tfdoc/get_started/os_setup.html
(英文不好的同学可以参考此网址,但是安装过程的说明不如上面的英文网址详细)

安装过程如下:
1.安装TensorFlow

pip3 install tensorflow-gpu

我用的是python3,所以安装是用命令pip3.
如果你不想获得gpu的支持,那么安装命令为:pip3 install tensorflow

安装完后,我想测试是否安装成功,打开python,输入import tensorflow后,出现如下问题:
>>> import tensorflow
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/init.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: dlopen(/usr/local/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib
Referenced from: /usr/local/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow.so
Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import tensorflow
  File "/usr/local/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 60, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: dlopen(/usr/local/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib
  Referenced from: /usr/local/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow.so
  Reason: image not found


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

需要关注的就是这句话:Error importing tensorflow. Unless you are using bagel,说明我需要安装bazel

2.安装bazel
bazel是谷歌的一款环境依赖包。使用homebrew的安装过程如下:

brew install bazel

安装后再次导入import tensorflow,仍然出现同样的错误。后来发现不能同时装tensorflowtensor flow-gpu(我两个都装了)。pip3卸载tenorflow-gpu后,以上错误就解决了。备注:我也试过卸载tensorflow而保留tensorflow-gpu,但是以上错误继续出现。我觉得可能是要支持gpu的计算,我的电脑还要安装一些东西。

远程机安装

相关文章

网友评论

    本文标题:安装TensorFlow步骤及要点

    本文链接:https://www.haomeiwen.com/subject/seanittx.html