-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Closed
Closed
Copy link
Labels
bugcategory: python bindingsconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete
Milestone
Description
System Information
- OS: Ubuntu 22.04.5 LTS (Jammy)
- Python Version: 3.10.12
- GCC Version: 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04.2)
- Architecture: x86_64
OpenCV Build Details
- Source: Git repository (https://github.com/opencv/opencv)
- Commit Date: Latest commit as of 2025-11-07
- Build Method: CMake
- Compiler: gcc-11
Detailed description
Problem Description
After compiling OpenCV from the latest git master (as of 2025-11-07), the Python bindings fail to import with a syntax error in the typing stub file.
Error Output
$ python3 -c "import cv2; print(cv2.__version__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.10/dist-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/usr/local/lib/python3.10/dist-packages/cv2/__init__.py", line 175, in bootstrap
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "/usr/local/lib/python3.10/dist-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
py_module = importlib.import_module(module_name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.10/dist-packages/cv2/typing/__init__.py", line 135
cv::Vec2d = _typing.Sequence[float]
^
SyntaxError: invalid syntax
Expected Behavior
OpenCV should import successfully without syntax errors.
Actual Behavior
Import fails immediately with a SyntaxError due to C++ namespace syntax (cv::) appearing in a Python file.
Steps to reproduce
CMake Configuration
cmake \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_C_FLAGS="-O2 -mtune=generic -ffunction-sections -fdata-sections" \
-DCMAKE_CXX_FLAGS="-O2 -mtune=generic -ffunction-sections -fdata-sections -Wno-deprecated" \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,--gc-sections" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--gc-sections" \
-DENABLE_FAST_MATH=ON \
-DWITH_OPENMP=ON \
-DWITH_FFMPEG=ON \
-DWITH_OPENCL=ON \
-DWITH_CUDA=ON \
-DWITH_TBB=ON \
-DWITH_V4L=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_DOCS=OFF \
-DBUILD_opencv_apps=OFF \
-DWITH_QT=OFF \
-DWITH_GTK=OFF \
-DWITH_IPP=ON \
-DCPU_BASELINE_DETECT=ON \
-DCPU_BASELINE=SSE3 \
-DCPU_DISPATCH=SSE4_1,SSE4_2,AVX,AVX2,AVX512_SKX,FP16 \
..Steps to Reproduce
- Clone OpenCV from git master (commit from around 2025-11-07)
- Configure with CMake using the flags above
- Build with make -j$(nproc)
- Install with make install
- Attempt to import: python3 -c "import cv2"
Edit: Manually editing /usr/local/lib/python3.10/dist-packages/cv2/typing/init.py to rename cv::Vec2d to Vec2d works around the problem.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugcategory: python bindingsconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete