Ubuntu16.04安装tensorflow遇到的问题总结

安装的过程主要参考TensorFlow中文社区

基于 VirtualEnv 的安装:

1.先安装必备的Python虚拟环境:

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

2.接下来, 建立一个全新的 virtualenv 环境. 为了将环境建在 ~/tensorflow 目录下, 执行:

$ virtualenv --system-site-packages ~/tensorflow
$ cd ~/tensorflow

3.然后, 激活 virtualenv:

$ source bin/activate  # 如果使用 bash

4.接着在用户名会出现(tensorflow)表明虚拟环境激活成功:

(tensorflow)$  # 终端提示符应该发生变化

5.在 virtualenv 内, 安装 TensorFlow:

(tensorflow)$ pip install --upgrade <$url_to_binary.whl>
注意:<$url_to_binary.whl>这个应该换成下面的地址,不然会报错:
# 仅使用 CPU 的版本
$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

# 开启 GPU 支持的版本 (安装该版本的前提是已经安装了 CUDA sdk)
$ pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

import tensorflow as tf 报错:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module>
    from tensorflow.python import *
  File "/home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 22, in <module>
    from tensorflow.python.client.client_lib import *
  File "/home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/client_lib.py", line 35, in <module>
    from tensorflow.python.client.session import InteractiveSession
  File "/home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 11, in <module>
    from tensorflow.python import pywrap_tensorflow as tf_session
  File "/home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: /home/python/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header



猜你喜欢

转载自blog.csdn.net/weixin_42007359/article/details/80161284