# cv::error: (-2:Unspecified error) Could not create window in function 'cv::namedWindow'

- **ID:** `opencv/highgui-window-could-not-be-created`
- **Domain:** opencv
- **Category:** system_error
- **Error Code:** `-2`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The display server (X11, Wayland, or macOS Quartz) is not available, or the window manager is not running.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.5 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

1. **import os
os.environ['OPENCV_IO_ENABLE_OPENCL'] = '0'
# Or simply avoid namedWindow calls; save images to disk instead:
cv2.imwrite('output.jpg', img)
# For debugging, print image shape instead of displaying.** (95% success)
   ```
   import os
os.environ['OPENCV_IO_ENABLE_OPENCL'] = '0'
# Or simply avoid namedWindow calls; save images to disk instead:
cv2.imwrite('output.jpg', img)
# For debugging, print image shape instead of displaying.
   ```
2. **sudo apt-get install xvfb
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
# Then run your OpenCV script** (90% success)
   ```
   sudo apt-get install xvfb
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
# Then run your OpenCV script
   ```

## Dead Ends

- **** — Qt backend also requires a display server; if no display is available, it will still fail. (50% fail)
- **** — If no X server is running, setting DISPLAY won't create one; the variable only works if X is already active. (70% fail)
- **** — Root privileges do not enable a display server; the error is about display availability, not permissions. (80% fail)
