Tensorflow安裝

TF安裝

Tensorflow windows安裝

安裝教程可以參考:https://www.tensorflow.org/install

本文給出簡單的安裝步驟

  1. 下載Anaconda python3.6版本進行安裝
  2. 配置環境變量,將目錄: D:\Anaconda3 和 D:\Anaconda3\Scripts 復制到path中保存
  3. cd D:\Anaconda3\envs
  4. 創建conda環境命名為tensorflow: conda create -n tensorflow python=3.6
  5. 激活conda環境: activate tensorflow
  6. 安裝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

  1. To install these packages for Python 2.7, issue the following command:

sudo apt-get install python-numpy python-dev python-pip python-wheel

  1. 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!

測試成功

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容