ImportError: libcuda.so.1: cannot open shared object file

Question:

When I run my code with TensorFlow directly, everything is normal.

However, when I run it in a screen window, I get the following error.

ImportError: libcuda.so.1: cannot open shared object file: No such file or directory

I have tried the command:

source /etc/profile

But it doesn’t work.

Cause I use ssh to connect to the servers, the screen is necessary.

How can I fix it?

Asked By: dwqy11

||

Answers:

Try to put libcuda.so.1 path to LD_LIBRARY_PATH environment variable.

example:

export LD_LIBRARY_PATH=/path/of/libcuda.so.1:$LD_LIBRARY_PATH
Answered By: Jethro Sandoval

Background

libcuda.so.1 is the library for interacting with the CUDA driver (as opposed to CUDA’s "Runtime API", for which you need libcudart.so.*.

Now, it’s quite possible to have the CUDA Toolkit properly installed, without the driver being properly installed. And this error could be the result of building a (non-statically-linked) CUDA application in this situation.

Alternatively, it could be the case that there’s some misconfiguration of the library search path – because normally, libcuda.so.* are supposed to be installed in some directory on that path!

So, what’s on that search path? As explained here, it is:

  1. directories from $LD_LIBRARY_PATH
  2. directories from /etc/ld.so.conf
  3. /lib
  4. /usr/lib

A typical scenario would be for /etc/ld.so.conf to add, say, /usr/lib/x86_64-linux-gnu; and for libcuda.so.* to be there.

Bottom line

Here’s what you should do:

  1. Make sure a(n up-to-date) CUDA driver has been properly installed. If it hasn’t, download and install it, problem solved.
  2. Locate the libcuda.so.1 file (e.g. using locate). If it’s been placed somewhere weird that’s not in the library search path – act as in step 1.
  3. If you wanted the driver library installed someplace weird, then add that path to your user’s $LD_LIBRARY_PATH.
Answered By: einpoklum

Steps to follow:
Find libcuda.so.1:

echo $LD_LIBRARY_PATH #path
sudo find /usr/ -name 'libcuda.so.*' #version

Then add to $LD_LIBRARY_PATH, in my case /usr/local/cuda-10.0/compat, with the following command, in terminal:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/compat
Answered By: TkrA

As my condition, I develop in docker container environment, I do the following steps:

  1. Confirm your docker container have run with nvidia gpu
  2. Find libcuda.so.1:
    sudo find /usr/ -name 'libcuda.so.*'
  3. Then add to $LD_LIBRARY_PATH, in my case /usr/local/cuda-11.5/compat, with the following command, in terminal:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.5/compat
Answered By: charles cao
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.