Mac安装TensorFlow 1.13.1后导入报错求助:缺失libcublas.8.0.dylib
Hey there, let’s work through this TensorFlow import error you’re stuck with on your Mac. The root issue here is that TensorFlow can’t find the libcublas.8.0.dylib library, which is part of the CUDA toolkit required for GPU support. Here are some practical fixes to try out:
1. Switch to the CPU-only TensorFlow version (if you don’t have an NVIDIA GPU)
Most modern Macs use AMD or Apple Silicon GPUs, which aren’t supported by NVIDIA’s CUDA toolkit. If you don’t have an NVIDIA GPU, you probably installed the GPU-enabled variant of TensorFlow by mistake. Uninstall it and install the CPU-only version instead:
Using pip:
pip uninstall tensorflow-gpu pip install tensorflow==1.13.1 --no-cache-dir
Using Anaconda:
conda uninstall tensorflow-gpu conda install tensorflow==1.13.1
2. Install CUDA 8.0 and cuDNN 6.0 (if you have an NVIDIA GPU)
TensorFlow 1.13.1’s GPU version requires specific CUDA and cuDNN versions. The error mentions libcublas.8.0.dylib, which is part of CUDA 8.0. Here’s how to set this up:
- Download and install the CUDA Toolkit 8.0 from NVIDIA’s archive (note: NVIDIA ended CUDA support for Mac after version 10.1, so 8.0 is the right match here for older NVIDIA-equipped Macs).
- Download cuDNN 6.0 (compatible with CUDA 8.0), extract the files, and copy them into your CUDA installation directory (usually
/usr/local/cuda-8.0/). - Add these environment variables to your shell config file (like
~/.bash_profileor~/.zshrc):export CUDA_HOME=/usr/local/cuda-8.0 export LD_LIBRARY_PATH=$CUDA_HOME/lib:$LD_LIBRARY_PATH export PATH=$CUDA_HOME/bin:$PATH - Restart your terminal and Jupyter Notebook to apply the changes.
3. Manually fix the rpath for the TensorFlow library
If you already have CUDA 8.0 installed but TensorFlow still can’t find the library, you can update the rpath (runtime library path) in the TensorFlow shared file using install_name_tool:
- First confirm the location of
libcublas.8.0.dylib(it should be at/usr/local/cuda-8.0/lib/libcublas.8.0.dylibif you installed CUDA correctly). - Run this command to add the correct rpath to the TensorFlow module:
install_name_tool -add_rpath /usr/local/cuda-8.0/lib /Users/solomon/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
This is a quick workaround, so make sure your CUDA setup is correct first before trying this.
4. Verify your environment setup
After making changes, double-check that your environment variables are set properly:
- In your terminal, run:
echo $CUDA_HOME echo $LD_LIBRARY_PATH - In Jupyter Notebook, run this code to confirm the paths are available to Python:
import os print(os.environ.get('CUDA_HOME')) print(os.environ.get('LD_LIBRARY_PATH'))
Hopefully one of these solutions gets TensorFlow importing correctly for you!
内容的提问来源于stack exchange,提问作者sarkar

