23

I am getting the following import error when I am trying to run a Python script in a conda environment

(squad) azada@scholar-fe00:~/Desktop/Toy-Problem-Team-2 $ python3 train.py 
Traceback (most recent call last):
  File "train.py", line 21, in <module>
    from tensorboardX import SummaryWriter
  File "/home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/tensorboardX/__init__.py", line 5, in <module>
    from .torchvis import TorchVis
  File "/home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/tensorboardX/torchvis.py", line 11, in <module>
    from .writer import SummaryWriter
  File "/home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/tensorboardX/writer.py", line 15, in <module>
    from .event_file_writer import EventFileWriter
  File "/home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/tensorboardX/event_file_writer.py", line 28, in <module>
    from .proto import event_pb2
  File "/home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/tensorboardX/proto/event_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
  File "/home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/google/protobuf/descriptor.py", line 47, in <module>
    from google.protobuf.pyext import _message
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/azada/miniconda3/envs/squad/lib/python3.6/site-packages/google/protobuf/pyext/_message.cpython-36m-x86_64-linux-gnu.so)

Writing the strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX command has the following output

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_DEBUG_MESSAGE_LENGTH

As you can see the required libgcc version is not present. But I am unable to understand why python is looking for GLIBCXX in the /usr directory?

Running the same command on the libstdc++.so.6 of my anaconda environment shows that the required version is present in the file.

I am using my university's computing cluster so I don't have the admin rights.

Is there any way that I can make Python use the libstdc++ of my conda environment instead of the one in the /usr directory?

Philip Withnall
  • 5,293
  • 14
  • 28
Aditya Azad
  • 268
  • 1
  • 2
  • 5

4 Answers4

48

I spent a day working on this having encountered the same exact problem working on my research university's computing cluster with the same specs as you, and I finally found the right Stack Overflow thread. None of the above answers here work, unfortunately, but I can say with very high confidence that the details in the linked thread should solve your problem even though the source of the error traceback was different.

To summarize, you'll need to add the path to the lib folder in anaconda to LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/path/to/conda/env/lib

In my case, I just did:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/anaconda3/lib

...and it worked like a charm!

nathan liang
  • 1,000
  • 2
  • 11
  • 22
  • 2
    To make the conda env automatically set/unset variables upon activating/deacivating, see this answer [here](https://stackoverflow.com/questions/46826497/conda-set-ld-library-path-for-env-only) – Gustavo Seabra May 10 '22 at 20:33
  • For tcsh what worked for me put `setenv LD_LIBRARY_PATH ~/path/to/miniconda3/lib:$LD_LIBRARY_PATH` in `~/.tcshrc` then `source ~/.tcshrc` – ru111 Jan 19 '23 at 14:16
  • To automate the path export use: `echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/' > $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh` – KarateKid Jan 24 '23 at 11:29
9

This is also worth a shot, since it was what ended up working for me:

conda install -c conda-forge libstdcxx-ng

Explanation: I got this error when trying to import tensorflow as tf:

ImportError: /opt/conda/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /opt/conda/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

and I already had libgcc-ng installed. It's also worth noting that I had added both conda library path and system library paths appended to LD_LIBRARY_PATH, but that did not work for me. So, YMMV.

scottlittle
  • 18,866
  • 8
  • 51
  • 70
2

solve it by downgrading to libgcc==5.2.0

Initially, try to install with pip but if you get the error: Could not download and compile the C core of igraph.. install it by conda

  • 3
    The version is not available `(squad) azada@scholar-fe00:~/Desktop/Toy-Problem-Team-2 $ conda search libgcc Loading channels: done # Name Version Build Channel libgcc 7.2.0 h69d50b8_2 pkgs/main ` – Aditya Azad Oct 17 '19 at 04:44
  • try those commands : conda install -c conda-forge igraph python-igraph conda install -c vtraag leidenalg conda install libgcc==7.2.0 – Yassine HAMDAOUI Oct 17 '19 at 04:51
-3

Run this code and your problem should be solved,

conda install -c conda-forge gcc
MD Mushfirat Mohaimin
  • 1,966
  • 3
  • 10
  • 22