首页 > 代码库 > TensorFlow安装-ubuntu

TensorFlow安装-ubuntu

windows下某些tensorflow例子跑不成功,比如https://www.tensorflow.org/tutorials/wide 中的例子报下面的错误:‘

‘NoneType‘ object has no attribute ‘bucketize‘

因此决定在Linux环境上安装tf。

 

楼主用的linux系统为ubuntu-16.04.2-desktop-amd64, 安装在virtualbox 5.1.18版本上。 

注意unbuntu需要是64位的!!! tensorflow官方安装包目前不支持32位的os。 

1. 配置pip环境

   1) 安装pip: 

sudo apt install python3-pip

 2) 更新pip源

   国外的pip源不稳定, 添加国内豆瓣的pip源

   在主目录下创建.pip文件夹

 mkdir ~/.pip

 然后在该目录下创建pip.conf文件编写如下内容:

[global]
trusted-host =  pypi.douban.com
index-url = http://pypi.douban.com/simple

 3) 将pip版本从8.1.1升级成9.0.1

 sudo -H pip3 install --upgrade pip

2. 下载tensorflow whl文件并安装

   https://pypi.python.org/pypi/tensorflow有tensorflow版本列表:

   技术分享

 我们选择与python 3.5对应的tensorflow版本。直接安装tensorflow whl的命令为: 

sudo -H pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl

  由于tensorflow的whl较大, 可能由于网络不稳定下载失败。 也可以用迅雷将whl下载下来,然后安装,对应安装命令为:

sudo -H pip3 install --upgrade tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl

 上面的whl路径根据实际情况修改。

   我这里安装log如下:

jason@jason-ub:/media/sf_vmshare$ sudo -H pip3 install --upgrade tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl 
Processing ./tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl
Requirement already up-to-date: six>=1.10.0 in /usr/lib/python3/dist-packages (from tensorflow==1.0.1)
Collecting numpy>=1.11.0 (from tensorflow==1.0.1)
  Downloading numpy-1.12.1-cp35-cp35m-manylinux1_x86_64.whl (16.8MB)
    100% |████████████████████████████████| 16.8MB 66kB/s 
Requirement already up-to-date: wheel>=0.26 in /usr/lib/python3/dist-packages (from tensorflow==1.0.1)
Collecting protobuf>=3.1.0 (from tensorflow==1.0.1)
  Downloading protobuf-3.2.0-cp35-cp35m-manylinux1_x86_64.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 174kB/s 
Collecting setuptools (from protobuf>=3.1.0->tensorflow==1.0.1)
  Downloading setuptools-34.3.2-py2.py3-none-any.whl (389kB)
    100% |████████████████████████████████| 399kB 717kB/s 
Collecting packaging>=16.8 (from setuptools->protobuf>=3.1.0->tensorflow==1.0.1)
  Downloading packaging-16.8-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools->protobuf>=3.1.0->tensorflow==1.0.1)
  Downloading appdirs-1.4.3-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow==1.0.1)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 1.3MB/s 
Installing collected packages: numpy, pyparsing, packaging, appdirs, setuptools, protobuf, tensorflow
  Found existing installation: pyparsing 2.0.3
    Not uninstalling pyparsing at /usr/lib/python3/dist-packages, outside environment /usr
  Found existing installation: setuptools 20.7.0
    Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed appdirs-1.4.3 numpy-1.12.1 packaging-16.8 protobuf-3.2.0 pyparsing-2.2.0 setuptools-34.3.2 tensorflow-1.0.1

3. 测试安装效果

    为了验证安装效果, 我们跑一下https://www.tensorflow.org/tutorials/wide中的线性模型示例。

    从https://github.com/tensorflow/tensorflow将tensorflow的所有代码下载下来。 

    然后进入tensorflow-master/tensorflow/examples/learn目录。 运行: 

     python3.5 wide_n_deep_tutorial.py --model_type=wide

    结果符合预期:

    技术分享

  注意直接用python不行, 默认python是 2.7版本。 

  技术分享

 也可以修改~/.bashrc, 添加:

alias python=‘/usr/bin/python3.5‘

 然后: 

source ~/.bashrc

 这样后续可以直接使用python命令。  

 

 如果有six包相关报错, 可以执行下面的命令安装six:

sudo easy_install --upgrade six

 

  

  

 

 

 

TensorFlow安装-ubuntu