Due to the latest Tutorial with YOLOv3/v4 in ipynb in Colab I came up with the following error message:

./darknet: error while loading shared libraries: libcuda.so.1: cannot open shared object file: No such file or directory

After googling, I found that the file "libcuda.so.1" is just a symlink, link to some libcuda.so.* file, in Colab the env-variable LD_LIBRARY_PATH should include the path of libcuda.so.1.
So, I have do the following,

Get information:

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

/usr/local/cuda-12.2/compat/libcuda.so.1

/usr/local/cuda-12.2/compat/libcuda.so.535.129.03

/usr/local/cuda-12.2/compat/libcuda.so.1

Set LD_LIBRARY_PATH with python:

import os
os.environ['LD_LIBRARY_PATH']='/usr/local/cuda-12.2/compat/libcuda.so.1'

The same error remains…

Anyone have some idea, appreciate of any help and suggestions

The following method did not help neither.

%env LD_LIBRARY_PATH = /usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/cuda-12.2/compat/libcuda.so.1

@eric-soderberg Hi, Eric, chould you please help me, I havn't accomplish one custom Training, I have tried YOLOv7-tiny, and now the YOLOv4-tiny, in colab I have the issue as above, the "can not find libcude.so.1"-Issue. Thank you so much in advance.

Correction: The original information of the LD_LIBRARY_PATH I got is

/usr/local/nvidia/lib:/usr/local/nvidia/lib64

Hi @AskForAFriend

Fixing libcuda.so.1 Missing Error in Google Colab

When using CUDA libraries in Google Colab, it's common to encounter shared library errors. Here’s a systematic approach to resolving the error involving libcuda.so.1.

Step 1: Verify Library Presence

First, check if the libcuda.so.1 file exists and identify its location using:

!sudo find /usr/ -name 'libcuda.so.*'

Assuming you find /usr/local/cuda-12.2/compat/libcuda.so.1 and it points to a valid shared library version like libcuda.so.535.129.03, proceed to the next step.

Step 2: Set LD_LIBRARY_PATH Correctly

The LD_LIBRARY_PATH should include the directory containing libcuda.so.1, not the file path itself. Set it correctly in Python:

import os

# Set the directory path where libcuda.so.1 is located
cuda_lib_path = '/usr/local/cuda-12.2/compat'
current_ld_library_path = os.environ.get('LD_LIBRARY_PATH', '')
new_ld_library_path = f"{cuda_lib_path}:{current_ld_library_path}"

# Update the environment variable
os.environ['LD_LIBRARY_PATH'] = new_ld_library_path
print("Updated LD_LIBRARY_PATH:", os.environ['LD_LIBRARY_PATH'])

Step 3: Restart the Runtime

Changes to environment variables in Colab do not take effect until you restart the runtime. Restart it by:

  • Navigating to Runtime -> Restart runtime from the Colab menu.

Step 4: Verify Library Path

After restarting, check that the LD_LIBRARY_PATH includes your directory:

!echo $LD_LIBRARY_PATH

Step 5: Test Library Accessibility

Ensure the system recognizes libcuda.so.1 in the updated path:

!ldconfig -p | grep libcuda.so.1

This command should list libcuda.so.1 if it’s correctly located.

Step 6: Execute Darknet

Run your Darknet command again. If set up properly, it should now find libcuda.so.1 without errors.

!./darknet detector train <your_config_file_path>

Troubleshooting Tips

  • Library Still Not Found? You might try setting the library path explicitly when executing your binary using LD_PRELOAD:

      !LD_PRELOAD=/usr/local/cuda-12.2/compat/libcuda.so.1 ./darknet <args>
  • Ensure GPU Usage: Confirm that your Colab session is using a GPU by checking the runtime type:


    • Go to Runtime -> Change runtime type and make sure 'GPU' is selected under Hardware Accelerator.

:H :i @jakaskerl ,

thanks for the reply, some advices are very helpful, I think I forgot to restart the runtime after setting the env_variable.
Since I am using free colab, thre might be some strange issues related to "CUDA"-topic, I think that might be the limition of GPU using.

Anyway, your very detailed reply is top top, thanks a lot.
I will tell my friend.