TensorFlow入门(2):安装

本文主要介绍在Linux和Mac环境中的TensorFlow的安装过程,由于windows没有安装过,所以不没有叙述。

环境准备

TensorFlow安装

验证测试


环境准备

首先需要系统安装python,最新的操作系统应该都自带了python,这里需要注意的就是python的版本默认安装一般都是2.7.x版本,如果需要python3,需要重新折腾。如果系统没有,参见大神廖雪封python安装,非常牛逼:
https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001374738150500472fd5785c194ebea336061163a8a974000
这里默认大家都已经安装好了python。

接下来就是python的安装工具pip,pip是干什么用的及如何安装也请参见:
https://pip.pypa.io/en/stable/reference/pip_install/
或者:
http://blog.csdn.net/liuchunming033/article/details/39578019

那么如果可以显示一下内容,说明基础的环境就是准备好了:

python -V
Python 2.7.13


pip -V
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

TensorFlow安装

过程其实并不复杂,只要是懂得基本的命令即可顺利安装。
python2.7环境安装: 

# Ubuntu/Linux 64-bit, CPU only, Python 2.7:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

#Ubuntu/Linux 64-bit, GPU enabled, Python 2.7. Requires CUDA toolkit 7.5 and CuDNN v4.
For other versions, see "Install from sources" below.
    $ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

#Mac OS X, CPU only:
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl

python3环境安装:

# Ubuntu/Linux 64-bit, CPU only, Python 3.4:
$ sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4. Requires CUDA toolkit 7.5 and CuDNN v4.
# For other versions, see "Install from sources" below.
$ sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl

# Mac OS X, CPU only:
$ sudo easy_install --upgrade six
$ sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py3-none-any.whl

验证测试

~-Air:basic$ python
Python 2.7.13 (default, Apr  4 2017, 08:47:57) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, tensorflow')
>>> sess = tf.Session()
2017-10-29 09:37:50.109695: 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.
2017-10-29 09:37:50.109741: 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.
2017-10-29 09:37:50.109760: 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.
2017-10-29 09:37:50.109776: 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.
2017-10-29 09:37:50.109792: 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 computations.
>>> print sess.run(hello)
Hello, tensorflow
>>>

注意这上面是安装了CUDA也就是用于GPU加速的组件,这一部分也需要安装,可以参见附录的文章进行安装。


http://www.tensorfly.cn/tfdoc/get_started/os_setup.html
https://www.leiphone.com/news/201606/ORlQ7uK3TIW8xVGF.html
http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html
https://pip.pypa.io/en/stable/reference/pip_install/
http://blog.csdn.net/liuchunming033/article/details/39578019
https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值