sys.path is only searched for Python modules. For dynamic linked libraries, the paths searched must be in LD_LIBRARY_PATH. Check if your LD_LIBRARY_PATH includes /usr/local/lib, and if it doesn't, add it and try again.

Some more information (source):

In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories; this is useful when debugging a new library or using a nonstandard library for special purposes. The environment variable LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so. I should note that, while LD_LIBRARY_PATH works on many Unix-like systems, it doesn't work on all; for example, this functionality is available on HP-UX but as the environment variable SHLIB_PATH, and on AIX this functionality is through the variable LIBPATH (with the same syntax, a colon-separated list).

To set LD_LIBRARY_PATH, use one of the following, ideally in your ~/.bashrc or equivalent file:

export LD_LIBRARY_PATH=/usr/local/lib

or

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

Use the first form if it's empty (equivalent to the empty string, or not present at all), and the second form if it isn't. Note the use of export.

Answer from Vinay Sajip on Stack Overflow
Top answer
1 of 8
182

sys.path is only searched for Python modules. For dynamic linked libraries, the paths searched must be in LD_LIBRARY_PATH. Check if your LD_LIBRARY_PATH includes /usr/local/lib, and if it doesn't, add it and try again.

Some more information (source):

In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories; this is useful when debugging a new library or using a nonstandard library for special purposes. The environment variable LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so. I should note that, while LD_LIBRARY_PATH works on many Unix-like systems, it doesn't work on all; for example, this functionality is available on HP-UX but as the environment variable SHLIB_PATH, and on AIX this functionality is through the variable LIBPATH (with the same syntax, a colon-separated list).

To set LD_LIBRARY_PATH, use one of the following, ideally in your ~/.bashrc or equivalent file:

export LD_LIBRARY_PATH=/usr/local/lib

or

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

Use the first form if it's empty (equivalent to the empty string, or not present at all), and the second form if it isn't. Note the use of export.

2 of 8
63

Ensure your libcurl.so module is in the system library path, which is distinct and separate from the python library path.

A "quick fix" is to add this path to a LD_LIBRARY_PATH variable. However, setting that system wide (or even account wide) is a BAD IDEA, as it is possible to set it in such a way that some programs will find a library it shouldn't, or even worse, open up security holes.

If your "locally installed libraries" are installed in, for example, /usr/local/lib, add this directory to /etc/ld.so.conf (it's a text file) and run ldconfig

The command will run a caching utility, but will also create all the necessary "symbolic links" required for the loader system to function. It is surprising that the make install for libcurl did not do this already, but it's possible it could not if /usr/local/lib is not in /etc/ld.so.conf already.

PS: it's possible that your /etc/ld.so.conf contains nothing but include ld.so.conf.d/*.conf. You can still add a directory path after it, or just create a new file inside the directory it's being included from. Dont forget to run ldconfig after it.

Be careful. Getting this wrong can screw up your system.

Additionally: make sure your python module is compiled against THAT version of libcurl. If you just copied some files over from another system, this wont always work. If in doubt, compile your modules on the system you intend to run them on.

🌐
GitHub
github.com › sahlberg › libnfs-python › issues › 41
ImportError: libnfs.so.13: cannot open shared object file: No such file or directory · Issue #41 · sahlberg/libnfs-python
October 26, 2020 - but when i use this module by import libnfs,it's wrong . the error is ImportError: libnfs.so.13: cannot open shared object file: No such file or directory
Author   sahlberg
Discussions

Python ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
Hi there! I am having this issue with using Python pandas. It was working fine up until I moved my venv folder and broke it, so I had to reinstall the packages and since then I get this error. Traceback (most recent call last): File "/home/nix/Desktop/Python/v21/v21.py", line 19, in import ... More on discourse.nixos.org
🌐 discourse.nixos.org
0
0
December 17, 2023
python 2.x - cannot open shared object file: No such file or directory - Raspberry Pi Stack Exchange
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI ... More on raspberrypi.stackexchange.com
🌐 raspberrypi.stackexchange.com
January 5, 2018
python - OSError: cannot open shared object file: No such file or directory even though file is in the folder - Stack Overflow
I've been fighting with this for quite some time now. I'm trying to install Yaafe for audio feature extraction. I follow instructions here: https://github.com/Yaafe/Yaafe Everything installs up ni... More on stackoverflow.com
🌐 stackoverflow.com
python - ImportError: libxxx: cannot open shared object file: No such file or directory - Stack Overflow
I am trying to build a Python package that interops with C++ code. I created a PyBind11 wrapper to do the interop. I created a setup.py file following the instructions here: from pybind11.setup_hel... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/learnpython › oserror cannot open shared object file: no such file or directory
r/learnpython on Reddit: OSError cannot open shared object file: No such file or directory
January 7, 2023 -

hi all, i'm trying to figure out what's wrong with the code for pytest ...

would appreciate your help (it seems adding the name of a string into the path..unknown why..

hereby the code

import sys
import pytest
import platform
from pathlib import Path

sys.path.append(r"./")
from mvpy_rest_server import NucRestRunner # noqa
import MvxGraph # noqa

DEFAULT_LIB_PATH = r"libc"
DEFAULT_MEMPOOL  = 1000
MAX_STR = 256
DEFAULT_PORT     = "7500"

current_dir = ""


@pytest.fixture
def nuc_rest_runner(pytestconfig):
    global current_dir
    current_dir = lib = pytestconfig.getoption("lib")
    if not lib:
        current_dir = lib = DEFAULT_LIB_PATH
    return NucRestRunner(lib, DEFAULT_MEMPOOL, DEFAULT_PORT)


@pytest.fixture()
def client(nuc_rest_runner):
    return nuc_rest_runner.app.test_client()

hereby the error:

ERROR tests/test_mvpy_rest_server.py::test_nuc_rest_runner_init - ValueError: ('Failed to init MvxGraphCore, due to exception:', OSError('libc/libMvxGraphCore.so: cannot open shared object file: No such file or directory'))

now the files are there .

the current path for the file:

"libc/MvxGraphCore"

, but if u an see it adds the name "lib" into the path 'libc**/lib**

and i can't figure out why.

🌐
NixOS Discourse
discourse.nixos.org › help
Python ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory - Help - NixOS Discourse
December 17, 2023 - Hi there! I am having this issue with using Python pandas. It was working fine up until I moved my venv folder and broke it, so I had to reinstall the packages and since then I get this error. Traceback (most recent call last): File "/home/nix/Desktop/Python/v21/v21.py", line 19, in import ...
Top answer
1 of 2
4

Change your code so that you print os.environ right before that exception occurs. That way you will see whether the Python process has the correct environment set or not. The other obvious thing to check are whether your Python process has sufficient permission to open and read libyaafe-python.so. Note that sudo by default limits the environment of the invoked command, for security reasons (see here, for instance).

2 of 2
2

I know this post is old, but if you cannot modify (or do not want to modify) LD_LIBRARY_PATH and you still need a way to load the shared object into memory in Python, then you can use this general approach.

import ctypes
ctypes.CDLL('/usr/local/lib/library.version.so', mode=ctypes.RTLD_GLOBAL)

For you, the call might look like:

import ctypes
ctypes.CDLL('/usr/local/lib/libyaafe-python.so', mode=ctypes.RTLD_GLOBAL)

And if you don't know the path beforehand, I've put together the following function that can recursively search a set of library paths for a specified library name (and version). Hope this helps!


# Given a library name, try to locate the library and load it in
#  global mode as a CDLL so that it is accessible to all code.
def load_library(libname, version=None, paths=("/usr/lib","/usr/local/lib",),
                 extensions=(".so",), prefixes=("","lib",),
                 recursive=True):
    import os, ctypes
    # This code will find all possible matches for the library, 
    #  and pick the first lexicographically.
    versions = set()
    for directory in paths:
        # Enumerate all files at that path (depending on "resursive" option).
        if recursive:
            file_paths = sum((
                [os.path.join(dirpath, f) for f in filenames]
                for (dirpath, dirnames, filenames) in os.walk(directory)
            ), [])
        else:
            file_paths = [
                os.path.join(directory,f) for f in os.listdir(directory)
                if not os.path.isdir(f)
            ]
        # Iterate over the files looking for the specified library.
        for path in file_paths:
            filename = os.path.basename(path)
            # Verify the file extension is allowed.
            ext = filename[len(filename)-filename[::-1].find('.')-1:] 
            # Examples of the value for 'ext' given a 'filename':
            #   "foo.bar" -> ".bar", "foobar" -> ""
            if (ext not in extensions): continue
            # Check that the library name is in file name.
            if (libname not in filename): continue
            # Check that the version is in the name (if it is specified).
            file_version = ".".join(filename.split('.')[1:-1])
            if ((version is not None) and (version != file_version)): continue
            # Extract the file name and check for matches against prefixes.
            name = filename[:(filename+'.').find('.')]
            for p in prefixes:
                if (p+libname == name): break
            else: continue
            # Now this filename matches the required:
            #   name preceding the first ".",
            #   file extension including last ".",
            #   version between first and last "." if that was specified,
            #   and it exists in one of the provided paths.
            versions.add(path)
            # Uncomment the following line to see the considered libraries.
            # print([path, filename, name, file_version, ext, os.path.islink(path)])
    # Raise an error if no versions could be found.
    if (len(versions) == 0):
        raise(FileNotFoundError(f"No library file found for '{libname}'{'' if version is None else ' version '+version}."))
    # Get the library path as the first element of the set of discovered versions.
    library_path = sorted(versions)[0]
    # Load the library globally (so it is accessible to later codes) and return its path.
    ctypes.CDLL(library_path, mode=ctypes.RTLD_GLOBAL)
    return library_path

And for your specific example the call to the function would look like:

load_library("yaafe-python")

As long as you called this before importing whatever module was failing to load, everything should work.

WARNINGS

  • This is written for POSIX systems (Ubuntu, macOS, ...)
  • This loads the library into the global C namespace, so I am not sure how it will handle duplicate declarations if something already exists and it might cause unexpected downstream consequences if a loaded library is overwritten.
🌐
Archeaopteryx
archeaopteryx.github.io › html › python-error-shared-library.html
python: error while loading shared libraries
The most likely suspects were the \lib, \lib64 and \usr directories. I searched fairly generally for .so files containing 'libpython' and \lib64 turned out to be a good guess · $ cd /lib64 $ find . -name 'libpython?.*.so*' ./libpython3.8.so.1.0 ./python2.7/config/libpython2.7.so ./libpython3.8.so ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 79386068 › importerror-libxxx-cannot-open-shared-object-file-no-such-file-or-directory
python - ImportError: libxxx: cannot open shared object file: No such file or directory - Stack Overflow
Verify there is an entry setting RUNPATH to $ORIGIN which is supposed to instruct the dynamic linker to add directory containing the module to its search path: $ readelf -d venv/lib/python3.10/site-packages/my_package/my_package.cpython-310...
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
OSError: cannot open shared object file: No such file or directory - Raspberry Pi Forums
July 26, 2023 - I am reaching out for some assistance with a Python program that involves acquiring data from a sensor using a third-party SDK. When I run the program on my laptop running Ubuntu, it works perfectly fine. However, I encountered an issue when attempting to run the same program on my Raspberry Pi 4. The error message I receive is as follows: "OSError: cannot open shared object file: No such file or directory...
🌐
GitHub
github.com › tensorflow › tensorflow › issues › 60326
ImportError: libtensorflow_cc.so.2: cannot open shared object file: No such file or directory · Issue #60326 · tensorflow/tensorflow
April 14, 2023 - But when I pip install this whl, import tensorflow got "ImportError: libtensorflow_cc.so.2: cannot open shared object file: No such file or directory". I found the whl file generated is only 80.64M. But I think it should be about 200M. But there has libtensorflow_cc.so.2 file under path tensorflow/bazel-bin/tensorflow. I don't know why it wasn't packed into the whl file. ... Traceback (most recent call last): File "<string>", line 1, in <module> File "/data1/envs/xtc3.9/lib/python3.9/site-packages/tensorflow/__init__.py", line 38, in <module> from tensorflow.python.tools import module_util as
Author   tensorflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 2285021 › error-when-running-python-3-13-web-app-python-erro
Error when running Python 3.13 Web App: "python: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directory" - Microsoft Q&A
June 17, 2025 - Hello, I am trying to run an Azure WebApp using the python 3.13 stack. However it won't even start up because I am getting this error: python: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or…
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson systems › jetson xavier nx
OSError: libcurand.so.10: cannot open shared object file:No such file or directory - Jetson Xavier NX - NVIDIA Developer Forums
July 21, 2023 - Hi, Description In my docker bash[sudo docker exec -it app1 bash], i got this error in python terminal, OSError: libcurand.so.10: cannot open shared object file:No such file or directory When importing torchvision by import torchvision Error ScreenShot - Environment TensorRT Version: 4.4.1 GPU Type: Nvidia Jetson Xavier NX CUDA Version: 10.2.89 CUDNN Version: 8.0.0.180 Operating System + Version: Ubuntu 18.04 Python Version (if applicable): 3.6.9 TensorFlow Version (if appl...
🌐
Stack Overflow
stackoverflow.com › questions › 76126892 › python-cannot-open-shared-object-file-no-such-file-or-directory-on-raspbian
linux - Python 'cannot open shared object file: No such file or directory' on Raspbian - Stack Overflow
OSerror: /home/pi/Desktop/proj/venv/lib/python3.7/site-packages/pvrecorder/lib/linux/i686/libpv_recorder.so: cannot open shared object file: No such file or directory
🌐
GitHub
github.com › nomic-ai › gpt4all › issues › 553
libllama.so: cannot open shared object file: No such file or directory · Issue #553 · nomic-ai/gpt4all
May 12, 2023 - Traceback (most recent call last): File "/home/pi/Desktop/venv/tst.py", line 1, in <module> import gpt4all File "/home/pi/Desktop/venv/lib/python3.9/site-packages/gpt4all/__init__.py", line 1, in <module> from . import gpt4all # noqa File "/home/pi/Desktop/venv/lib/python3.9/site-packages/gpt4all/gpt4all.py", line 6, in <module> from . import pyllmodel File "/home/pi/Desktop/venv/lib/python3.9/site-packages/gpt4all/pyllmodel.py", line 39, in <module> llmodel, llama = load_llmodel_library() File "/home/pi/Desktop/venv/lib/python3.9/site-packages/gpt4all/pyllmodel.py", line 32, in load_llmodel_l
Author   nomic-ai