ImportError: libstdc++.so.6

I’ve started my first project from python gemini backend template and even without changing anything, I get this error:

$ python main.py 
Traceback (most recent call last):
  File "/home/user/py-backed-gemini/main.py", line 4, in <module>
    import google.generativeai as genai
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/generativeai/__init__.py", line 45, in <module>
    from google.generativeai import caching
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/generativeai/caching.py", line 21, in <module>
    from google.generativeai import protos
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/generativeai/protos.py", line 74, in <module>
    from google.ai.generativelanguage_v1beta.types import *
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/__init__.py", line 21, in <module>
    from .services.cache_service import CacheServiceAsyncClient, CacheServiceClient
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/cache_service/__init__.py", line 16, in <module>
    from .async_client import CacheServiceAsyncClient
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/cache_service/async_client.py", line 32, in <module>
    from google.api_core import gapic_v1
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
    import grpc
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/grpc/__init__.py", line 22, in <module>
    from grpc import _compression
  File "/home/user/py-backed-gemini/.venv/lib/python3.11/site-packages/grpc/_compression.py", line 20, in <module>
    from grpc._cython import cygrpc
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
(.venv) py-backed-gemini-5878098:~/py-backed-gemini$
2 Likes

I ran into this same issue. Using a suggestion from this nixOS thread, I set the LD_LIBRARY_PATH in the nix config and rebuilt the environment. I’m not a nix expert, so I’m not sure if this is the proper way to accomplish this, but it made my app work!

Here is the relevant block in my dev.nix file:

# Sets environment variables in the workspace
env = {
      LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
};
4 Likes

This mf worked! Thank you

Wanted to update from the IDX team that we have identified the root cause and fixed this issue!

1 Like

Hi Alex - I’m trying to run a flask app that I cloned from github and I get a very similar error when trying to run numpy / pandas.

(.venv) pftrackr-82774451:~/dev/portfolio_tracker{dev}$ python main.py
Traceback (most recent call last):
  File "/home/user/dev/portfolio_tracker/main.py", line 1, in <module>
    from app import app
  File "/home/user/dev/portfolio_tracker/app/__init__.py", line 27, in <module>
    from app import routes, models
  File "/home/user/dev/portfolio_tracker/app/routes.py", line 12, in <module>
    import pandas as pd
  File "/home/user/dev/.venv/lib/python3.11/site-packages/pandas/__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.11 from "/home/user/dev/.venv/bin/python"
  * The NumPy version is: "1.25.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libstdc++.so.6: cannot open shared object file: No such file or directory