TensorFlow学习笔记(一补):使用Anaconda安装TensorFlow
2018-01-12 11:06
288 查看
建议参照最新的tensorflow安装步骤(Linux,官方网站经常访问不是很稳定,所以给了一个github的地址):https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/install/install_linux.md
最近,tensorflow网站上给出了新的使用Anaconda配置和安装Tensorflow的步骤,经过测试,在国内可以无障碍的访问。Anaconda 是一个基于python的科学计算包集合,目前支持Python 2.7,3.4,3.5,3.6。
注意:在安装过程中如果出现很长的报错,观察错误信息的末尾,如果是网络链接相关,就重新运行一遍语句即可(如出现进度条不动的情况,也可重新运行语句),Anaconda自身约500M,tensorflow所需软件包约几十M。
操作系统: Ubuntu 14.04
安装anaconda,在终端输入:
cd ~/Downloads
bash Anaconda-2.2.0-linux-x86_64.sh
view plain
copy
# Python 2.7
$ conda create -n tensorflow python=2.7 选这个。
# Python 3.4
$ conda create -n tensorflow python=3.4
# Python 3.5
$ conda create -n tensorflow python=3.5
[plain]
view plain
copy
$ source activate tensorflow
然后根据要安装的不同tensorflow版本选择对应的一条环境变量设置export语句(操作系统,Python版本,CPU版本还是CPU+GPU版本)
[plain]
view plain
copy
# Ubuntu/Linux 64-bit, CPU only, Python 2.7
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
# Mac OS X, CPU only, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py2-none-any.whl
# Mac OS X, GPU enabled, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.10.0-py2-none-any.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.4
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.5
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl
# Mac OS X, CPU only, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py3-none-any.whl
# Mac OS X, GPU enabled, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.10.0-py3-none-any.whl
最后根据是python 2还是3版本选择一句进行安装。
[plain]
view plain
copy
# Python 2
(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL
# Python 3
(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL
3.2 conda方式 ——选这个~
conda上面目前有人已经做好了tensorflow的pkg,但是版本不一定最新,且只有CPU版本,不支持GPU。
步骤也是首先激活conda环境,然后调用conda install 语句安装.
[plain]
view plain
copy
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
-------------------------------------------------------
# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
(tensorflow)$ conda install -c conda-forge tensorflow
--------------------------------或者------------------
选版本最新的
因此,执行下面代码来查看详细信息:
它就会告诉你,怎么来安装这个包,在终端执行:
上面的步骤完成后,从conda环境中退出:
[plain]
view plain
copy
(tensorflow)$ source deactivate
view plain
copy
$ source activate tensorflow
(tensorflow)$ # Your prompt should change.
# Run Python programs that use TensorFlow.
...
安装成功与否,我们可以测试一下。
在终端输入python,进入python编译环境,然后输入:
tf.__version__tf.__path__-------------------
# When you are done using TensorFlow, deactivate the environment.
(tensorflow)$ source deactivate
最近,tensorflow网站上给出了新的使用Anaconda配置和安装Tensorflow的步骤,经过测试,在国内可以无障碍的访问。Anaconda 是一个基于python的科学计算包集合,目前支持Python 2.7,3.4,3.5,3.6。
注意:在安装过程中如果出现很长的报错,观察错误信息的末尾,如果是网络链接相关,就重新运行一遍语句即可(如出现进度条不动的情况,也可重新运行语句),Anaconda自身约500M,tensorflow所需软件包约几十M。
操作系统: Ubuntu 14.04
1. 安装Anaconda
从anaconda官网(https://www.continuum.io/downloads)上下载linux版本的安装文件(推荐Python 2.7版本),运行sh完成安装。安装anaconda,在终端输入:
cd ~/Downloads
bash Anaconda-2.2.0-linux-x86_64.sh
2. 建立一个tensorflow的运行环境
[plain]view plain
copy
# Python 2.7
$ conda create -n tensorflow python=2.7 选这个。
# Python 3.4
$ conda create -n tensorflow python=3.4
# Python 3.5
$ conda create -n tensorflow python=3.5
3.在conda环境中安装tensorflow
在conda环境中安装tensorflow的好处是可以便捷的管理tensorflow的依赖包。分为两个步骤:激活上一步建立的名为tensorflow的conda环境;用conda或者pip工具安装Tensorflow,作者选择的是pip方式。3.1 pip方式
pip方式需要首先激活conda环境[plain]
view plain
copy
$ source activate tensorflow
然后根据要安装的不同tensorflow版本选择对应的一条环境变量设置export语句(操作系统,Python版本,CPU版本还是CPU+GPU版本)
[plain]
view plain
copy
# Ubuntu/Linux 64-bit, CPU only, Python 2.7
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
# Mac OS X, CPU only, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py2-none-any.whl
# Mac OS X, GPU enabled, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.10.0-py2-none-any.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.4
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp34-cp34m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, CPU only, Python 3.5
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl
# Mac OS X, CPU only, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py3-none-any.whl
# Mac OS X, GPU enabled, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.10.0-py3-none-any.whl
最后根据是python 2还是3版本选择一句进行安装。
[plain]
view plain
copy
# Python 2
(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL
# Python 3
(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL
3.2 conda方式 ——选这个~
conda上面目前有人已经做好了tensorflow的pkg,但是版本不一定最新,且只有CPU版本,不支持GPU。步骤也是首先激活conda环境,然后调用conda install 语句安装.
[plain]
view plain
copy
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
-------------------------------------------------------
# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
(tensorflow)$ conda install -c conda-forge tensorflow
--------------------------------或者------------------
anaconda search -t conda tensorflow
选版本最新的
因此,执行下面代码来查看详细信息:
anaconda show jjhelmus/tensorflow
它就会告诉你,怎么来安装这个包,在终端执行:
conda install --channel https://conda.anaconda.org/jjhelmus tensorflow
上面的步骤完成后,从conda环境中退出:
[plain]
view plain
copy
(tensorflow)$ source deactivate
4. 测试安装
[plain]view plain
copy
$ source activate tensorflow
(tensorflow)$ # Your prompt should change.
# Run Python programs that use TensorFlow.
...
安装成功与否,我们可以测试一下。
在终端输入python,进入python编译环境,然后输入:
import tensorflow as tf
tf.__version__tf.__path__-------------------
$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>
# When you are done using TensorFlow, deactivate the environment.
(tensorflow)$ source deactivate
相关文章推荐
- TensorFlow学习笔记(一补):使用Anaconda安装TensorFlow
- 使用anaconda安装tensorflow,opencv3,使其可以运行在jupyter python上
- 【Python】记录五:使用anaconda安装Tensorflow+在spyder和jupyter中启动Tensorflow
- win7系统中使用anaconda安装tensorflow,keras
- 在Window(操作系统64位)下使用Anaconda安装TensorFlow
- 先安装keras、TensorFlow后使用Anaconda安装Jupyter
- TensorFlow学习笔记(一):快速安装与使用TensorFlow
- 使用Anaconda安装TensorFlow
- TensorFlow(一):使用Anaconda安装TensorFlow
- TensorFlow学习笔记01:Win10下使用Anaconda安装TensorFlow
- 使用anaconda安装TensorFlow
- Ubuntu16.04lts使用Anaconda安装tensorflow并配置GPU
- 我在Suse 11 Sp3上使用anaconda安装TensorFlow的过程记录
- TensorFlow学习笔记(一):快速安装与使用TensorFlow
- 使用Anaconda安装TensorFlow
- Windows10下用Anaconda安装TensorFlow,并在pycharm中使用
- 使用anaconda在windows上安装tensorflow
- Windows下用Anaconda安装TensorFlow,并在pycharm中使用
- Ubuntu安装Tensorflow及anaconda环境下使用TensorFlow
- 人工智能开发环境 使用Anaconda安装TensorFlow