3

When I try to run a PyTorch program, it fails:

Could not load library libcudnn_cnn_infer.so.8. Error: libcuda.so: cannot open shared object file: No such file or directory
Please make sure libcudnn_cnn_infer.so.8 is in your library path!
Aborted

When I did apt-get for the cuda packages, and it was in a different directory than the library path. I copied the file and tried to paste it in the library path: /usr/lib/wsl/lib.

Turned out, the folder was read-only, and no matter what I did (e.g. chmod), it stayed that way. How should I edit the library path if the path is read-only?

***If I am missing any info, please ask

0

4 Answers 4

2

I solved this problem by typing export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/some/directory/ into bash.

1
  • In fact, this helped! The library was found in the environment by: find ../my-environment-folder/ -name "libcudnn_ops_infer.so.8" ../my-environment-folder/lib/python3.11/site-packages/nvidia/cudnn/lib/libcudnn_ops_infer.so.8 And then I used as you suggested: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../my-environment-folder/lib/python3.11/site-packages/nvidia/cudnn/lib python <my commands and parameters> Commented Feb 8 at 12:45
1

Error: error Could not load library libcudnn_ops_infer.so.8. Error: libcudnn_ops_infer.so.8: cannot open shared object file: No such file or directory Please make sure libcudnn_ops_infer.so.8 is in your library path! Aborted (core dumped)

Solution: Find where this file (libcudnn_ops_infer.so.8) is and add it to library path. You can follow the following steps:

Step-01 (Find lib path): You can use the find command with the -name option to search for the path of library where libcudnn_ops_infer.so.8 is located like:

sudo find / -type f -name libcudnn_ops_infer.so.8

Now choose the appropriate path based on your specific environment and requirements after running the above command.

Step-02 (Add lib path): You can update the LD_LIBRARY_PATH environment variable to include the path where the library is located.

For example: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/u/.conda/envs/bot/lib/python3.10/site-packages/torch/lib

In my case, the path was: “” export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/u/.conda/envs/work_virtual_env/lib/python3.10/site-packages/nvidia/cudnn/lib/””

Note: My OS was Ubantu 22.04 LTS

0

I had to use

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64_linux-gnu/
0

You can use this Python Package, to check Symbols in .so/.dll files. Or you implement your own C Library, and add it to all your Packages/Programs.

To install it, you can use pip install dlsym .

dlsym allows Python C extension modules to use symbols present in already loaded C libraries, without having to actually link these libraries. As a simple example, using pybind11:

double (* my_atan2)(double, double);
my_atan2 = reinterpret_cast<decltype(my_atan2)>(
    py::module::import("dlsym").attr("dlsym")("atan2").cast<uintptr_t>());

Obviously, linking against libm to get access to atan2 is not particularly difficult, but this approach also allows one to use e.g. numpy-provided BLAS/LAPACK functions which are available after importing numpy (regardless of whether the underlying implementation is OpenBLAS, MKL, or something else), fftw functions after importing pyfftw, or Tcl/Tk functions after importing tkinter (see tests for examples).

The main goal here is to simplify the compilation of such extension modules on machines where the C libraries may not be present by default, but where they can be “requested” by declaring an install_requires on the corresponding Python package.

Note that the path to the shared library is not actually passed as an argument to dlsym (unlike the POSIX dlsym(3). This is because the symbol search on Windows has to enumerate all loaded modules anyways, as one cannot just pass a module that transitively loads the symbol. On POSIX, we thus follow the same strategy for consistency (but enumerating all extension modules in sys.modules instead).

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 13, 2023 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .