VMware虚拟机上Ubuntu安装TensorFlow 1.0

作者:u012359995

1、安装VMware

安装的版本为 VMware-workstation-full-10.0.1-1379776

2、安装Ubuntu

网上下载ubuntu-16.10-desktop-amd64.iso 镜像

然后在VMware里面用创建新的虚拟机的方式去安装, 注意: 网络适配器直接使用默认的 NAT模式即可。
其它选项全部默认配置,启动并安装(安装各种软件包时可能比较慢,请耐心等待)

  • 注意安装过程中要填ubuntu系统的登录用户和密码,一定记住,后面在系统里一系列操作可能会用到

  • 第一次启动时可能会出现这样的错误提示:SMBus Host Controller not enabled ,解决方法是:

    • 重启ubuntu系统,在开始时按住shift键不放,直到出现系统安全模式界面为止
    • 选择Ubuntu的高级选项(Advanced options for Ubuntu)
    • 进入Ubuntu的恢复模式(Ubuntu, with Linux 4.7.x.x-generic (recovery mode))
    • 在Recovery Menu中选择root进入root shell 命令行
    • 输入命令: mount -o remount,rw / 回车;
    • 接下里输入命令: sudo vi /etc/modprobe.d/blacklist.conf 修改文件
    • 在文件最后添加一行 : blacklist i2c_piix4 保存关闭即可
    • 输入reboot命令重启系统后即可解决

3、使用xshell 连接 ubuntu(也可以直接在ubuntu系统里面操作,那么直接跳过该步骤即可)

1)首先检查是否安装ssh

  • 输入命令: ps -e |grep ssh

无反应即表示没有安装,

  • 输入以下命令安装:
    sudo apt-get install openssh-server

““

zhao@ubuntu:~$ ps -e |grep ssh
zhao@ubuntu:~$ sudo apt-get install openssh-server
[sudo] password for zhao: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ncurses-term openssh-sftp-server ssh-import-id
Suggested packages:
  ssh-askpass rssh molly-guard monkeysphere
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 257 not upgraded.
Need to get 635 kB of archives.
After this operation, 5,159 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 ncurses-term all 6.0+20160625-1ubuntu1 [243 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 openssh-sftp-server amd64 1:7.3p1-1 [39.8 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 openssh-server amd64 1:7.3p1-1 [342 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 ssh-import-id all 5.6-0ubuntu1 [10.2 kB]
Fetched 635 kB in 6s (98.0 kB/s)                                               
Preconfiguring packages ...
Selecting previously unselected package ncurses-term.
(Reading database ... 169977 files and directories currently installed.)
Preparing to unpack .../0-ncurses-term_6.0+20160625-1ubuntu1_all.deb ...
Unpacking ncurses-term (6.0+20160625-1ubuntu1) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../1-openssh-sftp-server_1%3a7.3p1-1_amd64.deb ...
Unpacking openssh-sftp-server (1:7.3p1-1) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../2-openssh-server_1%3a7.3p1-1_amd64.deb ...
Unpacking openssh-server (1:7.3p1-1) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../3-ssh-import-id_5.6-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.6-0ubuntu1) ...
Setting up ncurses-term (6.0+20160625-1ubuntu1) ...
Processing triggers for ufw (0.35-2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up openssh-sftp-server (1:7.3p1-1) ...
Processing triggers for systemd (231-9git1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up ssh-import-id (5.6-0ubuntu1) ...
Setting up openssh-server (1:7.3p1-1) ...
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:w+TAYBqjnsAxA/EGHMP1RmA1OnMFzs0PhdoydHgNB6M root@ubuntu (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:jaSjIFrJBTuDQrVY8Oe4dkbrtD9ADHMi6mPh6/YL294 root@ubuntu (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:m9XhelXJ6zZODzZN5S/UnbUaiLSIHCJwfhUPdMtjMhE root@ubuntu (ED25519)
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (231-9git1) ...
Processing triggers for ufw (0.35-2) ...
zhao@ubuntu:~$ ps -e |grep ssh
 4024 ?        00:00:00 sshd
zhao@ubuntu:~$ 

““

2)使用xshell连接

  • 在ubuntu里的命令窗口,输入 ifconfig 查看ip地址

  • xshell配置相关信息,协议:ssh , 端口:22,在用户身份验证设置里面输入安装时填写的用户名和密码

4、安装必不可少的python-pip和python-dev

1)输入命令:

sudo apt-get install python-pip python-dev


    zhao@ubuntu:~$ sudo apt-get install python-pip python-dev
    [sudo] password for zhao: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      libexpat1-dev libpython-all-dev libpython-dev libpython2.7-dev python-all python-all-dev python-pip-whl python-pkg-resources
      python-setuptools python-wheel python2.7-dev
    Suggested packages:
      python-setuptools-doc
    The following NEW packages will be installed:
      libexpat1-dev libpython-all-dev libpython-dev libpython2.7-dev python-all python-all-dev python-dev python-pip python-pip-whl
      python-pkg-resources python-setuptools python-wheel python2.7-dev
    0 upgraded, 13 newly installed, 0 to remove and 257 not upgraded.
    Need to get 30.2 MB of archives.
    After this operation, 46.1 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Y
    Get:1 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libexpat1-dev amd64 2.2.0-1 [120 kB]
    Get:2 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libpython2.7-dev amd64 2.7.12-3build1 [28.2 MB]
    Get:3 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libpython-dev amd64 2.7.11-2 [7,916 B]                              
    Get:4 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libpython-all-dev amd64 2.7.11-2 [992 B]                            
    Get:5 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 python-all amd64 2.7.11-2 [978 B]                                   
    Get:6 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 python2.7-dev amd64 2.7.12-3build1 [276 kB]                         
    Get:7 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 python-dev amd64 2.7.11-2 [1,166 B]                                 
    Get:8 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 python-all-dev amd64 2.7.11-2 [1,000 B]                             
    Get:9 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe amd64 python-pip-whl all 8.1.2-2ubuntu0.1 [1,115 kB]          
    Get:10 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe amd64 python-pip all 8.1.2-2ubuntu0.1 [145 kB]               
    Get:11 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 python-pkg-resources all 26.1.1-1 [126 kB]                         
    Get:12 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 python-setuptools all 26.1.1-1 [176 kB]                            
    Get:13 http://us.archive.ubuntu.com/ubuntu yakkety/universe amd64 python-wheel all 0.29.0-1 [48.0 kB]                            
    Fetched 30.2 MB in 2min 48s (179 kB/s)                                                                                           
    Selecting previously unselected package libexpat1-dev:amd64.
    (Reading database ... 172737 files and directories currently installed.)
    Preparing to unpack .../00-libexpat1-dev_2.2.0-1_amd64.deb ...
    Unpacking libexpat1-dev:amd64 (2.2.0-1) ...
    Selecting previously unselected package libpython2.7-dev:amd64.
    Preparing to unpack .../01-libpython2.7-dev_2.7.12-3build1_amd64.deb ...
    Unpacking libpython2.7-dev:amd64 (2.7.12-3build1) ...
    Selecting previously unselected package libpython-dev:amd64.
    Preparing to unpack .../02-libpython-dev_2.7.11-2_amd64.deb ...
    Unpacking libpython-dev:amd64 (2.7.11-2) ...
    Selecting previously unselected package libpython-all-dev:amd64.
    Preparing to unpack .../03-libpython-all-dev_2.7.11-2_amd64.deb ...
    Unpacking libpython-all-dev:amd64 (2.7.11-2) ...
    Selecting previously unselected package python-all.
    Preparing to unpack .../04-python-all_2.7.11-2_amd64.deb ...
    Unpacking python-all (2.7.11-2) ...
    Selecting previously unselected package python2.7-dev.
    Preparing to unpack .../05-python2.7-dev_2.7.12-3build1_amd64.deb ...
    Unpacking python2.7-dev (2.7.12-3build1) ...
    Selecting previously unselected package python-dev.
    Preparing to unpack .../06-python-dev_2.7.11-2_amd64.deb ...
    Unpacking python-dev (2.7.11-2) ...
    Selecting previously unselected package python-all-dev.
    Preparing to unpack .../07-python-all-dev_2.7.11-2_amd64.deb ...
    Unpacking python-all-dev (2.7.11-2) ...
    Selecting previously unselected package python-pip-whl.
    Preparing to unpack .../08-python-pip-whl_8.1.2-2ubuntu0.1_all.deb ...
    Unpacking python-pip-whl (8.1.2-2ubuntu0.1) ...
    Selecting previously unselected package python-pip.
    Preparing to unpack .../09-python-pip_8.1.2-2ubuntu0.1_all.deb ...
    Unpacking python-pip (8.1.2-2ubuntu0.1) ...
    Selecting previously unselected package python-pkg-resources.
    Preparing to unpack .../10-python-pkg-resources_26.1.1-1_all.deb ...
    Unpacking python-pkg-resources (26.1.1-1) ...
    Selecting previously unselected package python-setuptools.
    Preparing to unpack .../11-python-setuptools_26.1.1-1_all.deb ...
    Unpacking python-setuptools (26.1.1-1) ...
    Selecting previously unselected package python-wheel.
    Preparing to unpack .../12-python-wheel_0.29.0-1_all.deb ...
    Unpacking python-wheel (0.29.0-1) ...
    Setting up python-pip-whl (8.1.2-2ubuntu0.1) ...
    Setting up python-wheel (0.29.0-1) ...
    Setting up python-pkg-resources (26.1.1-1) ...
    Processing triggers for doc-base (0.10.7) ...
    Processing 1 added doc-base file...
    Setting up libexpat1-dev:amd64 (2.2.0-1) ...
    Processing triggers for man-db (2.7.5-1) ...
    Setting up libpython2.7-dev:amd64 (2.7.12-3build1) ...
    Setting up python-pip (8.1.2-2ubuntu0.1) ...
    Setting up python2.7-dev (2.7.12-3build1) ...
    Setting up python-all (2.7.11-2) ...
    Setting up libpython-dev:amd64 (2.7.11-2) ...
    Setting up python-setuptools (26.1.1-1) ...
    Setting up python-dev (2.7.11-2) ...
    Setting up libpython-all-dev:amd64 (2.7.11-2) ...
    Setting up python-all-dev (2.7.11-2) ...
    zhao@ubuntu:~$ 

注意,安装需要联网下载依赖包,可能比较慢,请耐心等待。

5、安装TensorFlow

网上大多使用在线安装的方式,但发现对应网址https://storage.googleapis.com/tensorflow/....根本无法访问,所以这里我改用了下载安装包的方式

1)访问 https://github.com/tensorflow/tensorflow/

如图,在 Installation 文档下(因为安装的python是2.7版本的,所以要下对应版本的TensorFlow)

这里写图片描述

下载完后得到一个文件

tensorflow-1.0.1-cp27-none-linux_x86_64.whl

大概30MB左右。

2)使用xshell将安装包上传到ubuntu上,输入命令:

sudo pip install tensorflow-1.0.1-cp27-none-linux_x86_64.whl

会出现以下错误,根据提示升级pip版本即可,


    zhao@ubuntu:~/Downloads$ pip install --upgrade pip
    Collecting pip
      Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
        18% |██████                          | 235kB 4.3kB/s eta 0:04:00Exception:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
        status = self.run(options, args)
      File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run
        wb.build(autobuilding=True)
      File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 750, in build
        self.requirement_set.prepare_files(self.finder)
      File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 370, in prepare_files
        ignore_dependencies=self.ignore_dependencies))
      File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 587, in _prepare_file
        session=self.session, hashes=hashes)
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 810, in unpack_url
        hashes=hashes
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 649, in unpack_http_url
        hashes)
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 871, in _download_http_url
        _download_url(resp, link, content_file, hashes)
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 595, in _download_url
        hashes.check_against_chunks(downloaded_chunks)
      File "/usr/lib/python2.7/dist-packages/pip/utils/hashes.py", line 46, in check_against_chunks
        for chunk in chunks:
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 563, in written_chunks
        for chunk in chunks:
      File "/usr/lib/python2.7/dist-packages/pip/utils/ui.py", line 139, in iter
        for x in it:
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 552, in resp_read
        decode_content=False):
      File "/usr/share/python-wheels/urllib3-1.15.1-py2.py3-none-any.whl/urllib3/response.py", line 353, in stream
        data = self.read(amt=amt, decode_content=decode_content)
      File "/usr/share/python-wheels/urllib3-1.15.1-py2.py3-none-any.whl/urllib3/response.py", line 320, in read
        flush_decoder = True
      File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
        self.gen.throw(type, value, traceback)
      File "/usr/share/python-wheels/urllib3-1.15.1-py2.py3-none-any.whl/urllib3/response.py", line 242, in _error_catcher
        raise ReadTimeoutError(self._pool, None, 'Read timed out.')
    ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
    You are using pip version 8.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    zhao@ubuntu:~/Downloads$ pip install --upgrade pip

注意 升级可能会失败,继续重试即可,直到安装成功,会出现以下信息。


    zhao@ubuntu:~/Downloads$ pip install --upgrade pip
    Collecting pip
      Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
        100% |████████████████████████████████| 1.3MB 19kB/s 
    Installing collected packages: pip
    Successfully installed pip-8.1.2
    You are using pip version 8.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    zhao@ubuntu:~/Downloads$ pip install --upgrade pip
    Requirement already up-to-date: pip in /home/zhao/.local/lib/python2.7/site-packages

3) 安装其它相关依赖包

因为安装tensorflow时会下载一些依赖的包,但连接国外的网站不太稳定,所以这里还是使用下载安装包的方式去安装依赖包,主要有两个包比较大,一个是:numpy,一个是:protobuf

  • numpy包比较大(16MB左右),建议去下面网址下载对应版本,使用本地安装的方式。

https://pypi.python.org/pypi/numpy

在安装TensorFlow时可以看到依赖包对应的版本,这里使用的 numpy-1.12.1-cp27-cp27mu-manylinux1_x86_64.whl

下载完并使用xshell上传到ubuntu,同样执行命令:

sudo pip install numpy-1.12.1-cp27-cp27mu-manylinux1_x86_64.whl

出现 Successfully 即表示成功。


    zhao@ubuntu:~/Downloads$ sudo pip install numpy-1.12.1-cp27-cp27mu-manylinux1_x86_64.whl 
    [sudo] password for zhao: 
    The directory '/home/zhao/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    The directory '/home/zhao/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    Processing ./numpy-1.12.1-cp27-cp27mu-manylinux1_x86_64.whl
    Installing collected packages: numpy
    Successfully installed numpy-1.12.1
    zhao@ubuntu:~/Downloads$ 

注意 加sudo,否则会报没有权限的错误。

  • 另一个依赖包 protobuf

下载网址:
https://pypi.python.org/pypi/protobuf/3.2.0

下载得到: protobuf-3.2.0-cp27-cp27mu-manylinux1_x86_64.whl

上传并安装: sudo pip install protobuf-3.2.0-cp27-cp27mu-manylinux1_x86_64.whl

  • 最后执行命令:

sudo pip install tensorflow-1.0.1-cp27-none-linux_x86_64.whl

出现


    zhao@ubuntu:~/Downloads$ sudo pip install tensorflow-1.0.1-cp27-none-linux_x86_64.whl
    The directory '/home/zhao/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    The directory '/home/zhao/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    Processing ./tensorflow-1.0.1-cp27-none-linux_x86_64.whl
    Requirement already satisfied: wheel in /usr/lib/python2.7/dist-packages (from tensorflow==1.0.1)
    Requirement already satisfied: protobuf>=3.2.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.0.1)
    Collecting mock>=2.0.0 (from tensorflow==1.0.1)
      Downloading mock-2.0.0-py2.py3-none-any.whl (56kB)
        100% |????????????????????????????????| 61kB 92kB/s 
    Requirement already satisfied: numpy>=1.11.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.0.1)
    Collecting werkzeug>=0.11.10 (from tensorflow==1.0.1)
      Downloading Werkzeug-0.12.1-py2.py3-none-any.whl (312kB)
        100% |????????????????????????????????| 317kB 20kB/s 
    Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.0.1)
    Requirement already satisfied: setuptools in /usr/lib/python2.7/dist-packages (from protobuf>=3.2.0->tensorflow==1.0.1)
    Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow==1.0.1)
      Downloading funcsigs-1.0.2-py2.py3-none-any.whl
    Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow==1.0.1)
      Downloading pbr-2.0.0-py2.py3-none-any.whl (98kB)
        100% |????????????????????????????????| 102kB 21kB/s 
    Installing collected packages: funcsigs, pbr, mock, werkzeug, tensorflow
    Successfully installed funcsigs-1.0.2 mock-2.0.0 pbr-2.0.0 tensorflow-1.0.1 werkzeug-0.12.1
    zhao@ubuntu:~/Downloads$ 

出现Successfully installed ...表示成功!

6、运行TensorFlow示例


    zhao@ubuntu:~$ python
    Python 2.7.12+ (default, Sep 17 2016, 12:08:02) 
    [GCC 6.2.0 20160914] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    >>> hello = tf.constant('hello, TensorFlow')
    >>> sess = tf.Session()
    2017-03-21 14:47:46.672234: 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-03-21 14:47:46.672329: 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-03-21 14:47:46.672353: 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(20)
    >>> print sess.run(a+b)
    30
>>> 
  • 也可以把测试脚本写到一个python文件中,使用 python xxx.py 命令执行
发表评论

0个评论

我要留言×

技术领域:

我要留言×

留言成功,我们将在审核后加至投票列表中!

提示x

人工智能开发框架知识库已成功保存至我的图谱现在你可以用它来管理自己的知识内容了

删除图谱提示×

你保存在该图谱下的知识内容也会被删除,建议你先将内容移到其他图谱中。你确定要删除知识图谱及其内容吗?

删除节点提示×

无法删除该知识节点,因该节点下仍保存有相关知识内容!

删除节点提示×

你确定要删除该知识节点吗?