linux下部署tensorflow环境(二)

来源:互联网 发布:医院的网络咨询赚钱吗 编辑:程序博客网 时间:2024/06/05 23:08

1、在安装好 anaconda后,即可通过anaconda安装tensorflow

anaconda安装请参考:http://blog.csdn.net/lzc4869/article/details/78697223

(1)为Anaconda创建一个python3.5(或者3.6都行,随便)的环境,环境名称为tensorflow ,输入下面命令:

conda create -n tensorflow pip python=3.6

(2)启动tensorflow的环境:

source activate tensorflow

(3)当不使用tensorflow时,关闭tensorflow环境,命令为:

source deactivate tensorflow

(4)安装cpu版本的TensorFlow

 pip install --upgrade --ignore-installed tensorflow

(5)运行test.py验证脚本

import tensorflow as tfhello = tf.constant('Hello, TensorFlow!')sess = tf.Session()print(sess.run(hello))

运行不报错即为安装成功

(6)如何不激活环境即可使用tensorflow环境

#退出tensorflow环境source deactivate tensorflow#运行pip install tensorflowpip install  --upgrade pip

2、直接在python3.6中安装

(1)安装cpu版本的TensorFlow

sudo pip install --upgrade --ignore-installed tensorflow

(2)测试是否安装完成

import tensorflow as tfhello = tf.constant('Hello, TensorFlow!')sess = tf.Session()print(sess.run(hello))

(3)报错,权限不够

因为anaconda安装的时候用户默认为root,所以装其他的装不上。
更改anaconda目录的用户为xqt(原来是root)否则会导致安装不上,权限不够。

sudo chown -R xqt:xqt anaconda3/