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!
測試成功