ubuntu14.04系统中安装tensorflow(cpu版)

来源:互联网 发布:淘宝充话费怎么充 编辑:程序博客网 时间:2024/06/06 17:23

一.tensorflow的环境
ubuntu16.04的环境、系统自带pythond的环境
1、进入窗口的模式:
输入Python的命令,发现已经存在python。
2、输入以下命令安装pip

sudo apt-get install python-pip python-dev
  • 1
  • 1


3、安装pip

sudo pip install --upgrade https://ci.tensorflow.org/view/Nightly/job/nightly-matrix-cpu/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label=cpu-slave/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-1.2.0rc1-cp27-none-linux_x86_64.whl此处的链接为:https://github.com/tensorflow/tensorflow寻找自己需要的软件包
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

会出现如下的错误:

4、此处需要更新pip

sulei@sulei:~$ pip install --upgrade pip
  • 1
  • 2
  • 1
  • 2


5、继续执行上面的命令

 sudo pip install --upgrade https://ci.tensorflow.org/view/Nightly/job/nightly-matrix-cpu/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label=cpu-slave/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-1.2.0rc1-cp27-none-linux_x86_64.whl
  • 1
  • 2
  • 1
  • 2

结果:

安装成功:

6、测试
进入python

>>> import tensorflow as tf>>> hello = tf.constant('Hello, TensorFlow!')>>> sess = tf.Session()2017-06-07 22:31:06.638258: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.2017-06-07 22:31:06.638339: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.2017-06-07 22:31:06.638376: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.>>> print sess.run(hello)Hello, TensorFlow!>>> a = tf.constant(10)>>> b = tf.constant(32)>>> print sess.run(a+b)42
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

7、IDEA的安装
好用的IDE有很多,本文介绍的是Komodo IDE的免费版Komodo Edit。在Linux下打开它的官网(点击链接http://komodoide.com/download/edit-linux64/#)
下载解压后,进入解压目录;
在终端的命令下进入目录并进行

sulei@sulei:~/文档/Komodo$ ./install.sh nter directory in which to install Komodo. Leave blank andpress 'Enter' to use the default [~/Komodo-Edit-10].Install directory: ==============================================================================Komodo Edit 10 has been successfully installed to:    /home/sulei/Komodo-Edit-10You might want to add 'komodo' to your PATH by adding the install dir to you PATH. Bash users can add the followingto their ~/.bashrc file:    export PATH="/home/sulei/Komodo-Edit-10/bin:$PATH"Or you could create a symbolic link to 'komodo', e.g.:    ln -s "/home/sulei/Komodo-Edit-10/bin/komodo" /usr/local/bin/komodoDocumentation is available in Komodo or on the web here:    http://docs.activestate.com/komodoPlease send us any feedback you have through one of thechannels below:    komodo-feedback@activestate.com    irc://irc.mozilla.org/komodo    https://github.com/Komodo/KomodoEdit/issuesThank you for using Komodo.==============================================================================
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

根据路径找到这个文件,并打开

进行设置:

补充:
1、安装virtualenv

sulei@sulei:~$ sudo pip install virtualenv
  • 1
  • 2
  • 1
  • 2

这里写图片描述
2、安装numpy和matplotlib

sulei@sulei:~$ sudo pip install numpysulei@sulei:~$ sudo pip install matplotlib
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

这里写图片描述
此处出现matplotlib的安装错误:
这里写图片描述
如果matplotlib 装不上需要先安装其依赖的包libpng和freetype
安装libpng:

sudo apt-get install libpng-dev
  • 1
  • 1

这里写图片描述
安装freetype:

cd ~/Downloadswget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.10.tar.gztar zxvf freetype-2.4.10.tar.gzcd freetype-2.4.10/./congfiguremakesudo make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7



安装matplotlib

sudo pip install matplotlib
  • 1
  • 1


安装成功
3、安装OpenCV
下载opencv的发行版源码:

https://github.com/opencv/opencv/releases/tag/2.4.13.2tar -vxzf opencv-2.4.13.2.tar.gz安装编译源码的依赖:sudo apt-get install build-essentialsudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-devsudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这里写图片描述
进入源码目录并配置:

cd opencv-2.4.13.2/mkdir releasecd releasecmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

编译安装:

makesudo make install
  • 1
  • 2
  • 1
  • 2

进入Python Console,在Python Console中输入:

import cv2
  • 1
  • 1

这里写图片描述

如果没有报错,则说明opencv安装好了


第一步:安装pip工具

sudo apt-get install python-pip

第二步:安装tensorflow-cpu版

sudo pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl

或:sudo pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

第三步:打开sublime-text3 使用SFTP连接Ubuntu系统出现如下错误

The SSH host key has changed. This could indicate a potential security breach, or that the domain you are connecting to recently moved servers.If you are confident this is not a security breach you can delete the old host key and try again. 1. Win XP: Start > Run > regedit.exe    Win Vista/7: Start > regedit 2. Expand to HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys and delete the entry including @22:10.0.83.202

打开windows7下按步骤打开并删除相应记录

第四步:linux上测试tensor测试文件

test.py

import numpyimport tensorflow as tfhello = tf.constant("hello,tensorflow")sess = tf.session()PRint sess.run(hello)a = tf.constant(10)b = tf.constant(20)print sess.run(a+b)