TF安装
Tensorflow windows安装
安装教程可以参考:https://www.tensorflow.org/install
本文给出简单的安装步骤
- 下载Anaconda python3.6版本进行安装
- 配置环境变量,将目录: D:\Anaconda3 和 D:\Anaconda3\Scripts 复制到path中保存
- cd D:\Anaconda3\envs
- 创建conda环境命名为tensorflow: conda create -n tensorflow python=3.6
- 激活conda环境: activate tensorflow
- 安装cpu版本的TensorFlow到conda环境中: pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp36-cp36m-win_amd64.whl
tensorflow安装完毕。
Tensoerflow ubuntu安装
Installing with virtualenv
sudo apt-get install python3-pip python3-dev python-virtualenv
virtualenv --system-site-packages -p python3 ~/tensorflow
source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
source ~/tensorflow/bin/activate.csh # csh or tcsh
pip3 install --upgrade tensorflow
If failed (typically because you invoked a pip version lower than 8.1), install TensorFlow in the active virtualenv environment by issuing a command of the following format:
pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp35-cp35m-linux_x86_64.whl
Note that you must activate the virtualenv environment each time you use TensorFlow. If the virtualenv environment is not currently active, invoke one of the following commands:
source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
source ~/tensorflow/bin/activate.csh # csh or tcsh
When you are done using TensorFlow, you may deactivate the environment by invoking the deactivate function as follows:
deactivate
TensorFlow ubuntu安装(源码编译安装) CPU版本
参考文献:https://www.tensorflow.org/install/install_sources
克隆最新代码
git clone https://github.com/tensorflow/tensorflow
build a specific branch
cd tensorflow
git checkout Branch //If want to work with the r1.0 release instead of the master release, issue the following command: git checkout r1.0
Install Bazel
https://bazel.build/versions/master/docs/install.html
Install TensorFlow Python dependencies
- To install these packages for Python 2.7, issue the following command:
sudo apt-get install python-numpy python-dev python-pip python-wheel
- To install these packages for Python 3.n, issue the following command:
sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel
Configure the installation
cd tensorflow
./configure
Build the pip package
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
Install the pip package
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.2.1-py2-none-any.whl
测试安装
打开cmd,敲入以下命令
python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
系统输出
Hello, TensorFlow!
测试成功