求助:无NVIDIA GPU的MacOS系统下如何成功安装CuPy
Hey there, I’ve run into this exact issue before on macOS without an NVIDIA GPU—let’s walk through how to get CuPy’s CPU-only version installed properly.
First, prep your build environment
macOS requires some tools to compile CuPy from source (since pre-built CPU-only wheels aren’t always available for macOS). Start by installing Xcode Command Line Tools if you haven’t already:
xcode-select --install
Follow the prompts to complete the installation—this gives you the gcc/clang compilers needed for the build.
Option 1: Install via pip with CPU-only mode
The key here is to tell CuPy to skip CUDA detection entirely. Run this command, which sets an environment variable to disable CUDA checks during installation:
CUPY_NO_CUDA=1 pip install cupy
If you’re using a specific Python version (like your 3.7 env), make sure you’re using the pip associated with that environment (e.g., pip3.7 instead of pip if needed).
Option 2: Install from source (if pip install fails)
If the pip method still hits issues, compiling from source with the --no-cuda flag will work. You already cloned the repo earlier, so just adjust your install command:
git clone https://github.com/cupy/cupy.git cd cupy git submodule update --init pip install -e . --no-cuda
The --no-cuda flag tells the setup script to ignore CUDA entirely and build only the CPU-compatible components.
Why your earlier attempts failed
All the commands you tried before didn’t explicitly disable CUDA detection. CuPy’s default behavior is to look for a CUDA environment first, and since macOS doesn’t have NVIDIA’s CUDA toolkit installed, it threw the "CUDA environment is invalid" error you saw. By setting CUPY_NO_CUDA=1 or using --no-cuda, we bypass that check entirely.
Verify the installation
Once installed, test it out in Python to make sure everything works:
import cupy as cp test_array = cp.array([1, 2, 3]) print(test_array)
If you see array([1, 2, 3]) printed without errors, you’re good to go!
内容的提问来源于stack exchange,提问作者Nold

