[Fixed] ValueError: libcublas.so.*[0-9] not found in the system path – Cublas

by
Ali Hasan
cublas django django-rest-framework

The Problem:

A user is attempting to use the ultralytics library in a Django REST Framework project and is encountering an error stating that libcublas.so.*[0-9] cannot be found in the system path. The user has installed the library using Poetry, but the issue persists when importing it.

The Solutions:

Solution 1: Skipping PyTorch Versions

To resolve the issue with libcublas dependency, you can skip PyTorch versions 2.0.1 and 2.1.0 in your pyproject.toml file:

[tool.poetry.dependencies]
torch = ">=2.0.0, !=2.0.1, !=2.1.0"

This will ensure that your project does not use these problematic versions of PyTorch.

After making the change, run the following commands to update your Poetry environment:

poetry lock --no-update
poetry install

Solution 2: Install NVIDIA CUDA Toolkit

To resolve this error, install the NVIDIA CUDA Toolkit on your system. CUDA is a parallel computing platform and programming model developed by NVIDIA. It allows developers to leverage the power of GPUs for accelerated computing.

Steps for Ubuntu:

  1. Update your system:

    sudo apt-get update
    
  2. Install the CUDA Toolkit:

    sudo apt-get install nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc
    
  3. Restart your system to apply the changes.

Once CUDA is installed, the CUDA libraries, including libcublas.so, will be available on your system path. You should then be able to import and use the ultralytics library in your Django project without encountering the error.

Solution 3: Install the library directly in the virtual environment

When you encounter the error "ValueError: libcublas.so.*[0-9] not found in the system path", it indicates that the necessary library dependency is not found in the system path. To resolve this issue, instead of installing the library using your dependency manager (in this case, poetry), try installing it directly in the virtual environment. This can be done using the following command:

pip3 install "library_name"

Replace "library_name" with the actual name of the library you are trying to import. By installing the library directly in the virtual environment, you ensure that it is available to the project and can be imported without errors.

Solution 4: Install Nvidia Dependencies

Install the necessary Nvidia dependencies by adding the following lines to your poetry venv / pyproject.toml:

[tool.poetry.dependencies]
nvidia-ml-py3=22.2.0
nvtx=23.3.1

Solution 5: pyproject.toml Adjustment

To resolve the issue, add the following lines to your pyproject.toml file:

torch = ">=2.0.0, !=2.0.1, !=2.1.0"

Then, run poetry install to install the necessary Nvidia libraries.

This approach restricts the installation of specific versions of the PyTorch library that are known to cause compatibility issues with ultralytics. By excluding versions 2.0.1 and 2.1.0, you ensure that a compatible version of PyTorch is installed.

After the installation, you should be able to import and use the ultralytics library without encountering the ValueError: libcublas.so.*[0-9] not found in the system path error.

Q&A

How to solve ValueError: libcublas.so.*[0-9] not found in the system path error?

Update PyTorch to 2.1.1 or modify pyproject.toml to skip versions 2.0.1 and 2.1.0.

Can I fix the error without updating PyTorch?

Yes, install CUDA on your system.

Is there a workaround for other libraries with the same error?

Try installing the library directly in the virtual environment using pip3.