Resolve 'ImportError - libcublas.so.9.0 - cannot open shared object file No such file or directory'
Fix import error "ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory"
This error occurs when a required shared library file named "libcublas.so.9.0" is either missing or inaccessible. The library file is associated with CUDA, a parallel computing platform created by NVIDIA. To fix this error, you need to ensure CUDA is installed correctly, locate the missing library file, update the system library paths, and refresh the environment. This guide provides step-by-step instructions and an example to help you resolve the "ImportError: libcublas.so.9.0" error.
Here are the steps you can follow to resolve this issue:
-
Verify CUDA installation: Check if CUDA is correctly installed on your system. You can do this by running the following command in your terminal:
nvcc --version
If CUDA is installed, it will display the version number. If CUDA is not installed, you'll need to install it before proceeding.
-
Locate the missing library file: Search for the "libcublas.so.9.0" file on your system. It is usually located in the CUDA installation directory, specifically within the "lib64" or "lib" subdirectory. For example, the file path could be "/usr/local/cuda-9.0/lib64/libcublas.so.9.0". Make a note of the correct path.
-
Update the system library paths: Add the directory containing the "libcublas.so.9.0" file to your system's library path. This can be done by modifying the LD_LIBRARY_PATH environment variable. Run the following command, replacing "/path/to/libcublas.so.9.0" with the actual path you found in the previous step:
export LD_LIBRARY_PATH=/path/to/libcublas.so.9.0:$LD_LIBRARY_PATH
You can also add this line to your shell's configuration file (e.g., ~/.bashrc or ~/.bash_profile) to make the change persistent.
-
Refresh the environment: To apply the changes made to the library path, either restart your terminal or run the following command to reload the environment variables:
source ~/.bashrc
-
Test the fix: Try running the application or script that was previously causing the error. The "libcublas.so.9.0" file should now be found, and the error should no longer occur.
Note: The specific version number in the library file name may differ based on your CUDA installation. Adjust the file name accordingly in the steps above.
Example: Let's assume you have CUDA installed in the directory "/usr/local/cuda-9.0" and the "libcublas.so.9.0" file is located at "/usr/local/cuda-9.0/lib64/libcublas.so.9.0". To fix the error, you would follow these steps:
- Open a terminal.
- Run the command
nvcc --version
to verify CUDA installation. - Locate the "libcublas.so.9.0" file at "/usr/local/cuda-9.0/lib64/libcublas.so.9.0".
- Add the library path to the LD_LIBRARY_PATH environment variable:
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64/libcublas.so.9.0:$LD_LIBRARY_PATH
- Refresh the environment:
source ~/.bashrc
- Retry running your application or script to confirm that the error is resolved.
Remember to adjust the paths in the above steps according to your system's setup.