||
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) $
进入沙箱后,执行下面的命令来安装TensorFlow:
(tensorflow) $ pip install tensorflow==1.1.0
默认安装所需的依赖,直至安装成功。
照着官方文档录入一个简单例子:
(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/)
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-13 00:14
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社