Keywords: TensorFlow | CUDA | libcublas.so.10.0 | Ubuntu | Environment_Variables
Abstract: This article provides a comprehensive analysis of the common libcublas.so.10.0 shared object file not found error when installing TensorFlow GPU version on Ubuntu 18.04 systems. Through systematic problem diagnosis and environment configuration steps, it offers complete solutions ranging from CUDA version compatibility checks to environment variable settings. The article combines specific installation commands and configuration examples to help users quickly identify and resolve dependency issues between TensorFlow and CUDA libraries, ensuring the deep learning framework can correctly recognize and utilize GPU hardware acceleration.
Problem Background and Error Analysis
When installing TensorFlow GPU version on Ubuntu 18.04 operating system, users frequently encounter the ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory error. This error indicates that TensorFlow cannot find the required CUDA library files during runtime, even when CUDA 10.1 and cuDNN have been correctly installed in the system.
Environment Diagnosis and Version Compatibility
First, it's essential to verify the current CUDA installation status. Running nvcc -V and nvidia-smi commands can confirm the CUDA driver and toolkit version information. In the example scenario, the system shows CUDA 10.1 installed, but TensorFlow version 1.13.1 requires CUDA 10.0 library files, creating a version mismatch issue.
Different TensorFlow versions have specific compatibility requirements for CUDA and cuDNN. TensorFlow 1.13.x series typically requires CUDA 10.0 and cuDNN 7.4 or higher. When the CUDA version installed in the system doesn't match what TensorFlow expects, library file not found errors occur.
Solution: Installing Compatible CUDA Version
The most reliable solution is to install CUDA 10.0, which is compatible with the TensorFlow version. Download the CUDA 10.0 installation package from NVIDIA's official archive, then use the following command sequence for installation:
sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda-10-0
These commands first install the CUDA repository deb package, then add NVIDIA's GPG key, update the package manager, and finally install the core components of CUDA 10.0.
cuDNN Configuration and Installation
After installing CUDA 10.0, the corresponding cuDNN version needs to be installed. Download cuDNN v7.5.0 for CUDA 10.0 from the NVIDIA developer website, then perform the following operations:
sudo cp -P cuda/targets/ppc64le-linux/include/cudnn.h /usr/local/cuda-10.0/include/
sudo cp -P cuda/targets/ppc64le-linux/lib/libcudnn* /usr/local/cuda-10.0/lib64/
sudo chmod a+r /usr/local/cuda-10.0/lib64/libcudnn*
These commands copy cuDNN header files and library files to the CUDA installation directory and set appropriate read permissions.
Environment Variable Configuration
Proper configuration of environment variables is crucial for resolving library file not found issues. Add the following lines to the user's .bashrc file:
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
The PATH environment variable ensures the system can find CUDA executable files, while LD_LIBRARY_PATH tells the dynamic linker where to look for shared library files. After configuration, execute source ~/.bashrc or restart the terminal session to make the changes effective.
Alternative Solution Analysis
Besides installing compatible CUDA versions, there are several other possible solutions. In some CUDA 10.1 installations, the libcublas.so.10.0 file might be installed in the /usr/local/cuda-10.2/lib64 directory. In this case, the problem can be temporarily resolved by adding this path to LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Another approach is to create a symbolic link, connecting /usr/local/cuda-10.0 to /usr/local/cuda:
sudo ln -s /usr/local/cuda-10.0 /usr/local/cuda
This way, TensorFlow will find the required library files in the expected location.
Verification and Testing
After completing all configurations, verify whether TensorFlow can correctly import and use GPU. Execute the following test in the Python environment:
python3
>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
If True is returned, it indicates that TensorFlow has been successfully configured and can use GPU for computation. If problems persist, check whether the TensorFlow version is compatible with the installed CUDA version and reinstall specific TensorFlow versions if necessary.
Best Practices and Preventive Measures
To avoid similar library file not found issues, it's recommended to carefully consult the version compatibility table in the official documentation before installing TensorFlow. The TensorFlow website provides detailed tested build configurations, listing the CUDA and cuDNN version requirements for each TensorFlow version.
During installation, using virtual environments to manage Python package dependencies is advised to avoid system-level package conflicts. Additionally, regularly updating drivers and maintaining CUDA toolkit version consistency are effective methods for preventing such problems.
Through systematic environment configuration and version management, TensorFlow GPU version can run stably in various deep learning tasks, fully leveraging hardware acceleration advantages.