Search code examples
pythonpython-3.xnumpygccwindows-subsystem-for-linux

Issue with numpy in WSL2: libgcc_s.so.1: cannot open shared object file: No such file or directory


I'm trying to get a python project running that uses numpy down the line and am getting an ImportError issue. I can't seem to resolve and unfortunately I haven't found a useful answer yet, so I'm hoping for help here. This is all running in Windows WSL2 Ubuntu. Here is the latest I can do to reproduce the issue. This is in an empty directory with no other code.

If everything worked right, you would be out of a job.:~/src/pythontest$ python3 -m venv venv
If everything worked right, you would be out of a job.:~/src/pythontest$ source venv/bin/activate
(venv) If everything worked right, you would be out of a job.:~/src/pythontest$ pip install numpy
Collecting numpy
  Using cached numpy-1.26.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
Installing collected packages: numpy
Successfully installed numpy-1.26.2
WARNING: There was an error checking the latest version of pip.
(venv) If everything worked right, you would be out of a job.:~/src/pythontest$ python
Python 3.9.13 (main, May 17 2022, 14:19:07)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 24, in <module>
    from . import multiarray
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/core/overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libgcc_s.so.1: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/__init__.py", line 130, in <module>
    from numpy.__config__ import show as show_config
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/__config__.py", line 4, in <module>
    from numpy.core._multiarray_umath import (
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 50, in <module>
    raise ImportError(msg)
ImportError:

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.9 from "/home/flamebaud/src/pythontest/venv/bin/python"
  * The NumPy version is: "1.26.2"

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

Original error was: libgcc_s.so.1: cannot open shared object file: No such file or directory


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/flamebaud/src/pythontest/venv/lib/python3.9/site-packages/numpy/__init__.py", line 135, in <module>
    raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.```

Solution

  • I managed to resolve this issue by setting the LD_LIBRARY_PATH variable in my ~/.bashrc file:

    export LD_LIBRARY_PATH="/home/linuxbrew/.linuxbrew/lib/gcc/5:$LD_LIBRARY_PATH"

    It's important to note I had to set it specifically to the version directory of gcc for it to work. I tried it further up the tree with no results.