Skip to content

Fixing 'GLIBCXX_3.4.30' Not Found Error in Conda Environments

Problem Statement

When trying to import the librosa library in a Conda virtual environment on Linux systems, you may encounter the following error:

/home/user/anaconda3/envs/env_name/lib/python3.9/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/user/anaconda3/envs/env_name/lib/python3.9/site-packages/scipy/fft/_pocketfft/pypocketfft.cpython-39-x86_64-linux-gnu.so)

This error occurs when the system's GNU C++ standard library (libstdc++) is outdated and doesn't include the required GLIBCXX_3.4.30 version symbol needed by newer packages like SciPy.

WARNING

This issue typically affects Debian-based distributions (like Ubuntu and Debian itself) where the system-provided libstdc++ version may be older than what's required by Conda packages compiled with newer toolchains.

Checking Your Current GLIBCXX Version

Before proceeding with solutions, verify which GLIBCXX versions are available on your system:

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

If GLIBCXX_3.4.30 is missing from the output, you'll need one of the solutions below.

The most reliable solution is to install a newer version of GCC and libstdc++ directly in your Conda environment:

bash
conda install -c conda-forge libstdcxx-ng=12

Alternatively, you can install the complete GCC toolchain:

bash
conda install -c conda-forge gcc=12.1.0

This approach ensures compatibility between all packages in your environment without affecting system libraries.

Solution 2: Update SciPy Package

Sometimes the issue arises from version mismatches between SciPy and your standard library:

bash
# Upgrade SciPy to the latest version
pip install scipy --upgrade

# Or if using conda
conda update scipy

Recent versions of SciPy may have better compatibility or different library requirements.

INFO

Check your current versions with:

bash
conda list | grep libstdcxx-ng
pip list | grep scipy

Solution 3: Downgrade SciPy (If Update Doesn't Work)

If updating doesn't resolve the issue, try downgrading to a compatible version:

bash
conda install -c anaconda scipy==1.9.1

Older versions of SciPy may have less stringent library requirements.

Solution 4: Modify Library Path

If newer libraries exist in your Conda environment but aren't being detected:

  1. First, check if your Conda environment has the required version:

    bash
    strings /path/to/your/conda/envs/your-env/lib/libstdc++.so.6 | grep GLIBCXX_3.4.30
  2. If the version is present in your Conda environment, add it to your library path:

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

For a permanent solution, add this line to your shell configuration file (.bashrc, .zshrc, etc.).

DANGER

Modifying LD_LIBRARY_PATH can sometimes cause conflicts with system libraries. Use this as a last resort if other solutions don't work.

As a last resort, you can link to your system's library:

bash
cd /home/ubuntu/anaconda3/envs/your_env/lib
mv libstdc++.so.6 libstdc++.so.6.old
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6

WARNING

This approach may break other packages in your Conda environment that require the specific version of libstdc++ that originally came with the environment.

Solution 6: Import Order Workaround

Some users have reported that changing import order can temporarily resolve the issue:

python
import torch  # Add this before importing librosa
import librosa

While not a permanent fix, this can help in some specific scenarios where library loading order affects symbol resolution.

Prevention and Best Practices

To avoid similar issues in the future:

  1. Use consistent channels when installing packages in Conda
  2. Keep your environment updated regularly:
    bash
    conda update --all
  3. Create new environments for major project changes rather than modifying existing ones
  4. Stick to conda-forge for better compatibility between packages

Conclusion

The 'GLIBCXX_3.4.30' not found error typically stems from a mismatch between your system's C++ library and the requirements of Python scientific packages. The recommended solution is to install updated libraries within your Conda environment using conda install -c conda-forge libstdcxx-ng=12 or conda install -c conda-forge gcc=12.1.0.

If you continue to experience issues, consider creating a new Conda environment with updated packages from the start, or using containerization solutions like Docker for more consistent environments across different systems.