Ubuntu14.04下安装Tensorflow遇到的问题

来源:互联网 发布:文字解密软件 编辑:程序博客网 时间:2024/05/22 03:30

安装步骤:

首先说说安装步骤,挺简单的,就是确认pip和Python的版本

pip -V

python

如果不是最新版本就更新一下

$sudo apt-get install python-pip python-dev

然后就是安装Tensorflow了

$pip install tensorflow # Python 2.7; CPU support (no GPU support)

$pip3 install tensorflow # Python 3.n; CPU support (no GPU support)

$pip install tensorflow-gpu # Python 2.7; GPU support

$pip3 install tensorflow-gpu # Python 3.n; GPU support 

如果上面的步骤不成功,就使用下面的命令:

$sudo pip install --upgradeTF_PYTHON_URL # Python 2.7

$sudo pip3 install --upgradeTF_PYTHON_URL # Python 3.N

各种版本的下载地址:

Python 2.7

CPU only:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp27-none-linux_x86_64.whl

GPU support:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp27-none-linux_x86_64.whl

Python 3.4

CPU only:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp34-cp34m-linux_x86_64.whl

GPU support:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp34-cp34m-linux_x86_64.whl

Python 3.5

CPU only:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp35-cp35m-linux_x86_64.whl

GPU support:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl

Python 3.6

CPU only:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp36-cp36m-linux_x86_64.whl

GPU support:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp36-cp36m-linux_x86_64.whl

验证tensorflow是否安装成功

  1. 启动终端,输入python
  2. 输入以下代码:
>>> import tensorflow as tf>>> hello = tf.constant('Hello, TensorFlow!')>>> sess = tf.Session()>>> print(sess.run(hello))
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

如果输出Hello, TensorFlow!则代表安装成功。


查看Tensorflow版本:


$ pip show tensorflow


问题:

安装之后测试发现以下问题,搜了很多安装经验,我感觉应该是我之前安装的Tensorflow有冲突,虽然显示安装成功了,运行却出错。试了好多办法都不可行,无奈我把Ubuntu重新装了一下,一切就正常了。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 104, in <module>
    from tensorflow.python.platform import test
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/test.py", line 53, in <module>
    import mock                # pylint: disable=g-import-not-at-top,unused-import
  File "/usr/local/lib/python2.7/dist-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 69, in <module>
    from pbr.version import VersionInfo
ImportError: No module named pbr.version


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow










原创粉丝点击