You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中CUDA启用失败求助:NUMBA_DISABLE_CUDA=1环境变量问题

Fixing Numba CUDA Support Error on 64-bit Windows

Hey there, let's work through this CUDA issue you're facing with Numba—super frustrating when you've followed all the setup steps and still hit errors, right? Let's break down the problem and tackle each possible cause one by one.

First: Check for the NUMBA_DISABLE_CUDA Environment Variable

The error message explicitly calls out this environment variable as a possible culprit, so let's start here:

  • Open Command Prompt (CMD) and run:
    echo %NUMBA_DISABLE_CUDA%
    
  • If the output is 1, that's definitely why CUDA is disabled. To fix this:
    1. Right-click "This PC" → Properties → Advanced System Settings → Environment Variables.
    2. Look for NUMBA_DISABLE_CUDA in either User Variables or System Variables.
    3. Either delete the variable entirely, or change its value to 0.
    4. Restart your terminal/IDE (this is crucial—changes won't take effect until you do this!) and re-run your code.

Second: Verify Numba Can Detect Your GPU

If the environment variable isn't the issue, let's check if Numba can actually see your GTX 960M:

  • Run this simple test script:
    from numba import cuda
    print("Detected GPUs:", cuda.gpus)
    
  • If the output is Detected GPUs: [], that means Numba isn't finding your GPU. Here's what to do next:
    1. Install/Reinstall CUDA Toolkit: Your GTX 960M supports CUDA Compute Capability 5.0, so stick with a compatible CUDA version (CUDA 11.x is a safe bet—avoid the very latest 12.x releases, as they drop support for older GPUs).
    2. Update System PATH: Make sure the CUDA bin directory is added to your system PATH. For example, if you installed CUDA 11.8, add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin to your PATH.
    3. Restart Your Machine: After installing CUDA or updating PATH, a full restart ensures all changes are applied.

Third: Ensure Version Compatibility

Sometimes mismatched versions between Numba, CUDA, and NumPy can cause issues:

  • Update Numba to the latest stable version:
    pip install numba --upgrade
    
  • Update NumPy as well (outdated NumPy can conflict with Numba's CUDA support):
    pip install numpy --upgrade
    
  • Double-check that your Numba version is compatible with your installed CUDA Toolkit (focus on major version matches, e.g., Numba 0.57+ works with CUDA 11.x).

Fourth: Tweak Your Test Code (Just to Be Sure)

Your original code looks fine, but adding a quick CUDA availability check can help diagnose issues earlier. Here's an adjusted version:

import numpy as np
from numba import vectorize, cuda

@vectorize(["float32(float32, float32)"], target='cuda')
def test(a, b):
    return a + b

def main():
    # Check if CUDA is available first
    if not cuda.is_available():
        print("Error: CUDA is not detected on your system!")
        return
    
    a = np.arange(1, 10, dtype=np.float32)
    b = np.arange(11, 20, dtype=np.float32)
    c = test(a, b)
    print("Result:", c)

if __name__ == "__main__":
    main()

Start with the environment variable check—it's the most likely fix here. If that doesn't work, move through the other steps one by one. You've already put in two weeks of troubleshooting, so let's get this sorted!

内容的提问来源于stack exchange,提问作者Gabeeeh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:26:40