gongzijingshang的个人博客分享 http://blog.sciencenet.cn/u/gongzijingshang

博文

MacOSHighSierra10.13.2的ensorflow的安装(anaconda,virtuale...

已有 2291 次阅读 2018-2-24 09:12 |个人分类:tensorflow|系统分类:科研笔记

1,首先是安装了anaconda

2,其实用anaconda也是可以直接安装tensorflow的,但是由于virtualenv 可以创建一个隔离的容器,便于查错,所以就用virtualenv来安装,但是根据教程http://tensorfly.cn/tfdoc/get_started/os_setup.html安装会出错:


jjj@bogon:~/tensorflow$

jjj@bogon:~/tensorflow$ virtualenv --system-site-packages -p python3 targetDirectory

Running virtualenv with interpreter /Users/jjj/anaconda/bin/python3

Using base prefix '/Users/jjj/anaconda'

New python executable in /Users/jjj/tensorflow/targetDirectory/bin/python3

Not overwriting existing python script /Users/jjj/tensorflow/targetDirectory/bin/python (you must use /Users/jjj/tensorflow/targetDirectory/bin/python3)

dyld: Library not loaded: @loader_path/../lib/libpython3.5m.dylib

 Referenced from: /Users/jjj/tensorflow/targetDirectory/bin/python3

 Reason: image not found

ERROR: The executable /Users/jjj/tensorflow/targetDirectory/bin/python3 is not functioning

ERROR: It thinks sys.prefix is '/Users/jjj/tensorflow' (should be '/Users/jjj/tensorflow/targetDirectory')

ERROR: virtualenv is not compatible with this system or executable


认为是由于我的python是在anaconda下安装的原因,所以参考https://stackoverflow.com/questions/44575994/virtualenv-not-compatible-with-this-system-or-executable,卸载后用anaconda重新安装:


pip uninstall virtualenv

conda install virtualenv


问题解决,后面的安装过程参照:http://www.epubit.com.cn/book/onlinechapter/53043

安装好后创建一个工作目录,这里直接在home下创建了一个tensorflow文件夹:
$ virtualenv --system-site-packages ~/tensorflow

然后进入该目录,激活沙箱:

$ cd ~/tensorflow$ source bin/activate (tensorflow) $

2.在virtualenv里安装TensorFlow

进入沙箱后,执行下面的命令来安装TensorFlow:

(tensorflow) $ pip install tensorflow==1.1.0

默认安装所需的依赖,直至安装成功。

3.运行TensorFlow

照着官方文档录入一个简单例子:

(tensorflow) $ pythonPython2.7.12(default,Oct112016,05:16:02)[GCC 4.2.1CompatibleApple LLVM 7.0.2(clang-700.1.81)] on darwinType"help","copyright","credits"or"license"for more information.>>>>>>import tensorflow as tf>>> hello = tf.constant('Hello,TensorFlow!')>>> sess = tf.Session()>>>print sess.run(hello)Hello,TensorFlow!

恭喜,TensorFlow环境已经安装成功了

在最后一步print会报错,


>>> print sess.run(hello)

 File "<stdin>", line 1

   print sess.run(hello)

            ^

SyntaxError: invalid syntax

这是由于python 3和python 2的print语法的变化,需要加上():

>>> print(sess.run(hello))

b'Hello,TensorFlow!'



ps:另外在运行tensorflow时会出现下列waring:

>>> sess = tf.Session()

2018-02-24 08:09:47.784759: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.

2018-02-24 08:09:47.784783: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.

2018-02-24 08:09:47.784791: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

2018-02-24 08:09:47.784798: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.

2018-02-24 08:09:47.784805: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU


有参考说没有对CPU进行优化的原因,具体可以参照(http://blog.rickdyang.me/2017-05/tensorflow-build/







https://blog.sciencenet.cn/blog-2414991-1100967.html

上一篇:MacOS High Sierra 10.13.2的 iraf2.16 的安装
下一篇:文件转换小工具
收藏 IP: 110.244.37.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

全部作者的其他最新博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-13 05:11

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部