Resolve these as two separate issues: align the AI package’s CUDA runtime with a compatible NVIDIA driver, then install OpenCV into the exact Python environment that runs the image-detection script.
1. Correct the CUDA/driver mismatch
The CUDA error explicitly indicates that the installed NVIDIA driver cannot support the CUDA runtime required by the package. CUDA compatibility depends on the driver and runtime versions being compatible.^1^
- In PowerShell, record the installed driver and the CUDA version it reports:
nvidia-smi - Install the latest compatible driver offered by the laptop manufacturer or NVIDIA. Microsoft recommends obtaining manually installed drivers from the device manufacturer’s official site and selecting the correct Windows version and architecture.^2^ Also check Settings → Windows Update → Advanced options → Optional updates. Driver updates listed there are not installed automatically.^3^
- Restart Windows and run
nvidia-smiagain. - If no newer compatible driver exists for the laptop/GPU, install a build of the AI framework that targets an older supported CUDA runtime. If this is PyTorch, use its Windows installation selector to choose an available CUDA build compatible with the driver, or choose CPU if GPU acceleration is unnecessary.^4^
Do not use the DDU/older-driver procedures from unrelated blue-screen cases unless the driver installation itself is corrupted or Windows is crashing. Your reported runtime error establishes a compatibility mismatch, not driver corruption.
2. Install cv2 in the interpreter actually running the script
Since reinstalling packages did not persistently solve the import error, check for multiple Python installations or virtual environments rather than repeating a global installation. A virtual environment has its own interpreter and package set.^5^
From the project directory, run:
python -c "import sys; print(sys.executable)"
python -m pip --version
python -m pip show opencv-python
python -m pip install --upgrade pip
python -m pip install opencv-python
python -c "import cv2; print(cv2.__version__)"
Using python -m pip is important: it invokes pip through the same interpreter used by python, instead of potentially calling a different pip.exe. OpenCV recommends its PyPI packages for normal Python installations.^6^
If the project already has .venv, activate and verify it first:
.\.venv\Scripts\Activate.ps1
python -c "import sys; print(sys.executable)"
python -m pip install opencv-python
python -c "import cv2; print(cv2.__version__)"
The interpreter path should end with .venv\Scripts\python.exe. Microsoft documents this check as the way to confirm that commands are running in the intended environment.^7^
If you use VS Code:
- Press Ctrl+Shift+P.
- Select Python: Select Interpreter.
- Choose
.venv\Scripts\python.exe, matching the path printed above. - Open Terminal → New Terminal and rerun the import test.
Use opencv-contrib-python instead of opencv-python only if the script needs OpenCV’s additional contributed modules. Avoid installing both variants in the same environment.
Expected result
-
nvidia-smiruns successfully, and the AI framework starts without the “driver is too old” message. -
python -c "import cv2; print(cv2.__version__)"prints an OpenCV version from the same terminal and interpreter used to launch the script.
References
- CUDA Compatibility — CUDA Compatibility - NVIDIA Documentation Hub
- Update drivers through Device Manager in Windows | Microsoft Support
- [Windows 11](https://support.microsoft.com/windows/hardware/drivers/automatically-get-recommended-and-updated-hardware-drivers#summary)
- Get Started Locally - PyTorch
- Select a Python environment for a project in Visual Studio
- Install OpenCV for Python with pip — OpenCV Tutorials
- Set up a Microsoft Fabric workload back end by using the OpenAPI Specification (Swagger)