简体   繁体   English

无法在Ubuntu 12.04 LTS上正确安装或加载Tensorflow,导致产生ImportError

[英]Unable to properly install or load Tensorflow on Ubuntu 12.04 LTS with resultant ImportError

I attempted the Anaconda installation for TensorFlow on my Ubuntu 12.04 LTS system, which went through, but while importing the library in Python, I came across an ImportError shown below. 我尝试在我的Ubuntu 12.04 LTS系统上安装 TensorFlow的Anaconda ,但是在用Python导入库时,我遇到了如下所示的ImportError。

I went through a solution given for a similar thread, but it didn't work for me. 我找到了一个类似线程的解决方案 ,但它对我不起作用。

Basically here's what I did for the installation: 基本上这就是我为安装做的事情:

$ conda create -n tensorflow python=2.7
$ source activate tensorflow
(tensorflow)$ conda install -c conda-forge tensorflow
(tensorflow)$ source deactivate
$ source activate tensorflow

Then from within the virtualenv I loaded Python, and tried to import tensorflow. 然后从virtualenv我加载Python,并尝试导入tensorflow。 What I got was the following error: 我得到的是以下错误:

>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/anirudh/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
  File "/home/anirudh/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 48, in <module>
from tensorflow.python import pywrap_tensorflow
  File "/home/anirudh/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
  File "/home/anirudh/anaconda/envs/tensorflow/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: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.19' not found (required by /home/anirudh/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

How do I sort this? 我该如何排序?

This error probably relates to you glibc version. 这个错误可能与你的glibc版本有关。 There are some topics regarding this: Where can I get a copy of the file libstdc++.so.6.0.15 有一些关于此的主题: 我在哪里可以获得文件libstdc ++。so.6.0.15的副本

First check whether the required version is on your system. 首先检查所需的版本是否在您的系统上。

    $ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

If it is not listed, you can try 如果未列出,您可以尝试

    $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt-get dist-upgrade

"sudo apt-get dist-upgrade" may not be required. 可能不需要“sudo apt-get dist-upgrade”。

You need to install libstdc++6 with some dependencies like gcc an g++ , at least gcc-4.6 version: 您需要安装libstdc ++ 6以及一些依赖项,例如gccg++ ,至少是gcc-4.6版本:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo apt-get install libstdc++6

Or you can install linux-headers and build-essential witch contains some useful tools like gcc compiler, make .... tools for compiling and building software from source. 或者你可以安装linux-headersbuild-essential witch包含一些有用的工具,比如gcc编译器, make ....工具,用于编译和构建源代码软件。

It happened for me in CentOS 7 它在CentOS 7中发生在我身上

Running python script in conda environment I got very similar error about "GLIBCXX_3.4.22..." required by tensorflow wrapper. 在conda环境中运行python脚本我得到了与tensorflow包装器所需的“GLIBCXX_3.4.22 ...”非常类似的错误。

In my case first I did was: 在我的情况下,我首先做的是:

"conda install libgcc" “conda install libgcc”

Some libraries were installed, but that didn't helped me. 安装了一些库,但这对我没有帮助。 I finally solved the issue by deleting "GLIBCXX" from the folder that came with Schroedinger maestro software that was installed earlier. 我终于通过删除之前安装的Schroedinger maestro软件附带的文件夹中的“GLIBCXX”来解决了这个问题。 I think, there was some sort of conflict between two libraries. 我想,两个图书馆之间存在某种冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM