I am currently using intel base macos10.14 python3.9 Anaconda
I have tried all the methods mentioned below:
pip install --upgrade pip setuptools wheel #successfully upgraded
pip install opencv-python
pip install scikit-build
pip install cython
pip install --no-use-pep517 opencv-python --verbose
pip install opencv-python==4.5.3.56 --verbose
pip install opencv-python==4.5.5.64
Non of the above method or library worked it still give me error.
Attached is the logs
I'm encountering an issue while trying to build the OpenCV Python package using CMake on macOS. I'm using the CMake generator 'Unix Makefiles', and while the configuration seems to be successful initially, I'm facing errors related to Python versions and syntax during the build process.
Here are the steps I'm taking and the errors I'm encountering:
I'm trying to build the OpenCV Python package using CMake with the 'Unix Makefiles' generator. The configuration starts successfully, but then it encounters warnings and errors related to Python versions and syntax during the build process. Despite having Python 3.9 installed, there are warnings and errors indicating issues with Python 2.7 compatibility and syntax errors. Here's a summary of the encountered errors and warnings:
Warnings about Python version discrepancies and syntax errors during the configuration process. Errors related to finding suitable Python versions and libraries, specifically mentioning Python 2.7 compatibility issues. Syntax errors related to _distutils_hack/init.py, indicating invalid syntax. I'm using Python 3.9 and macOS 10.14. I've tried various solutions such as setting the Python version explicitly in CMake, but none seem to resolve the issue.
Any insights or suggestions on how to resolve these errors would be greatly appreciated.
Logs:
--------------------------------
-- Trying 'Ninja' generator - failure
--------------------------------------------------------------------------------
-- Trying 'Unix Makefiles' generator - success
--------------------------------------------------------------------------------
Configuring Project
Working directory:
/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-install-sb5zorwb/opencv-python_df8240dc6b5e41d0ac89ecfa36c3d7dc/_skbuild/macosx-10.14-x86_64-3.9/cmake-build
Command:
/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/cmake/data/bin/cmake /private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-install-sb5zorwb/opencv-python_df8240dc6b5e41d0ac89ecfa36c3d7dc/opencv -G 'Unix Makefiles' --no-warn-unused-cli -DCMAKE_INSTALL_PREFIX:PATH=/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-install-sb5zorwb/opencv-python_df8240dc6b5e41d0ac89ecfa36c3d7dc/_skbuild/macosx-10.14-x86_64-3.9/cmake-install -DPYTHON_VERSION_STRING:STRING=3.9.19 -DSKBUILD:INTERNAL=TRUE -DCMAKE_MODULE_PATH:PATH=/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/skbuild/resources/cmake -DPYTHON_EXECUTABLE:PATH=/opt/anaconda3/envs/py39/bin/python -DPYTHON_INCLUDE_DIR:PATH=/opt/anaconda3/envs/py39/include/python3.9 -DPYTHON_LIBRARY:PATH=/opt/anaconda3/envs/py39/lib/libpython3.9.dylib -DPython_EXECUTABLE:PATH=/opt/anaconda3/envs/py39/bin/python -DPython_ROOT_DIR:PATH=/opt/anaconda3/envs/py39 -DPython_FIND_REGISTRY:STRING=NEVER -DPython_INCLUDE_DIR:PATH=/opt/anaconda3/envs/py39/include/python3.9 -DPython_NumPy_INCLUDE_DIRS:PATH=/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/numpy/core/include -DPython3_EXECUTABLE:PATH=/opt/anaconda3/envs/py39/bin/python -DPython3_ROOT_DIR:PATH=/opt/anaconda3/envs/py39 -DPython3_FIND_REGISTRY:STRING=NEVER -DPython3_INCLUDE_DIR:PATH=/opt/anaconda3/envs/py39/include/python3.9 -DPython3_NumPy_INCLUDE_DIRS:PATH=/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/numpy/core/include -DPYTHON3_EXECUTABLE=/opt/anaconda3/envs/py39/bin/python -DPYTHON3_INCLUDE_DIR=/opt/anaconda3/envs/py39/include/python3.9 -DPYTHON3_LIBRARY=/opt/anaconda3/envs/py39/lib/libpython3.9.dylib -DBUILD_opencv_python3=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DOPENCV_SKIP_PYTHON_LOADER=ON -DOPENCV_PYTHON3_INSTALL_PATH=python -DINSTALL_CREATE_DISTRIB=ON -DBUILD_opencv_apps=OFF -DBUILD_opencv_freetype=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_DOCS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.14 -DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 -DCMAKE_BUILD_TYPE:STRING=Release
Not searching for unused variables given on the command line.
-- The CXX compiler identification is AppleClang 10.0.0.10001145
-- The C compiler identification is AppleClang 10.0.0.10001145
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detected processor: x86_64
[33mCMake Warning (dev) at cmake/OpenCVUtils.cmake:144 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:64 (find_host_package)
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:620 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
[0m
-- Found PythonInterp: /opt/anaconda3/envs/py39/bin/python (found suitable version "3.9.19", minimum required is "2.7")
[33mCMake Warning at cmake/OpenCVDetectPython.cmake:81 (message):
CMake's 'find_host_package(PythonInterp 2.7)' found wrong Python version:
PYTHON_EXECUTABLE=/opt/anaconda3/envs/py39/bin/python
PYTHON_VERSION_STRING=3.9.19
Consider providing the 'PYTHON2_EXECUTABLE' variable via CMake command line
or environment variables
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:620 (include)
[0m
-- Found Python2: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 (found version "2.7.10") found components: Interpreter
[33mCMake Warning (dev) at cmake/OpenCVUtils.cmake:144 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:96 (find_host_package)
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:620 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
[0m
-- Found PythonInterp: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 (found version "2.7.10")
[33mCMake Warning (dev) at cmake/OpenCVDetectPython.cmake:140 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:620 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
[0m
-- Could NOT find PythonLibs: Found unsuitable version "3.9.19", but required is exact version "2.7.10" (found /opt/anaconda3/envs/py39/lib/libpython3.9.dylib)
Error processing line 1 of /opt/anaconda3/envs/py39/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 194
f'spec_for_{name}',
^
SyntaxError: invalid syntax
Remainder of file ignored
Error processing line 1 of /private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'add_shim'
Remainder of file ignored
Error processing line 1 of /opt/anaconda3/envs/py39/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 194
f'spec_for_{name}',
^
SyntaxError: invalid syntax
Remainder of file ignored
Error processing line 1 of /private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'add_shim'
Remainder of file ignored
Error processing line 1 of /opt/anaconda3/envs/py39/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 194
f'spec_for_{name}',
^
SyntaxError: invalid syntax
Remainder of file ignored
Error processing line 1 of /private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'add_shim'
Remainder of file ignored
[33mCMake Warning (dev) at cmake/OpenCVUtils.cmake:144 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:64 (find_host_package)
cmake/OpenCVDetectPython.cmake:280 (find_python)
CMakeLists.txt:620 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
[0m
-- Found PythonInterp: /opt/anaconda3/envs/py39/bin/python (found suitable version "3.9.19", minimum required is "3.2")
[33mCMake Warning (dev) at cmake/OpenCVDetectPython.cmake:140 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:280 (find_python)
CMakeLists.txt:620 (include)
[100%] Built target opencv_gapi
[100%] [34m[1mGenerate files for Python bindings and documentation[0m
Error processing line 1 of /opt/anaconda3/envs/py39/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 194
f'spec_for_{name}',
^
SyntaxError: invalid syntax
Remainder of file ignored
Error processing line 1 of /private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 152, in addpackage
exec line
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'add_shim'
Remainder of file ignored
Note: Class Feature2D has more than 1 base class (not supported by Python C extensions)
Bases: cv::Algorithm, cv::class, cv::Feature2D, cv::Algorithm
Only the first base class will be used
Note: Class detail_GraphCutSeamFinder has more than 1 base class (not supported by Python C extensions)
Bases: cv::detail::GraphCutSeamFinderBase, cv::detail::SeamFinder
Only the first base class will be used
[100%] Built target gen_opencv_python_source
Copying files from CMake output
creating directory _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/python/cv2.cpython-39-darwin.so -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/cv2.cpython-39-darwin.so
creating directory _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_eye.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_eye.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_eye_tree_eyeglasses.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_eye_tree_eyeglasses.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_frontalcatface.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_frontalcatface.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_frontalcatface_extended.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_frontalcatface_extended.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_frontalface_alt.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_frontalface_alt.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_frontalface_alt2.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_frontalface_alt2.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_frontalface_alt_tree.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_frontalface_alt_tree.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_frontalface_default.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_frontalface_default.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_fullbody.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_fullbody.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_lefteye_2splits.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_lefteye_2splits.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_licence_plate_rus_16stages.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_licence_plate_rus_16stages.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_lowerbody.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_lowerbody.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_profileface.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_profileface.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_righteye_2splits.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_righteye_2splits.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_russian_plate_number.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_russian_plate_number.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_smile.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_smile.xml
copying _skbuild/macosx-10.14-x86_64-3.9/cmake-install/share/opencv4/haarcascades/haarcascade_upperbody.xml -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/data/haarcascade_upperbody.xml
Copying files from non-default sourcetree locations
copying LICENSE.txt -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/LICENSE.txt
copying LICENSE-3RD-PARTY.txt -> _skbuild/macosx-10.14-x86_64-3.9/cmake-install/cv2/LICENSE-3RD-PARTY.txt
Traceback (most recent call last):
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/anaconda3/envs/py39/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
return _build_backend().build_wheel(wheel_directory, config_settings,
File "/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 410, in build_wheel
return self._build_with_temp_dir(
File "/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 395, in _build_with_temp_dir
self.run_setup()
File "/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 487, in run_setup
super().run_setup(setup_script=setup_script)
File "/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 462, in <module>
File "<string>", line 222, in main
File "/private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-build-env-nzql211t/overlay/lib/python3.9/site-packages/skbuild/setuptools_wrap.py", line 706, in setup
_classify_installed_files(
File "<string>", line 402, in _classify_installed_files_override
TypeError: _classify_installed_files() got an unexpected keyword argument 'cmake_install_dir'
[1;31merror[0m: [1msubprocess-exited-with-error[0m
[31m×[0m [32mBuilding wheel for opencv-python [0m[1;32m([0m[32mpyproject.toml[0m[1;32m)[0m did not run successfully.
[31m│[0m exit code: [1;36m1[0m
[31m╰─>[0m See above for output.
[1;35mnote[0m: This error originates from a subprocess, and is likely not a problem with pip.
[1;35mfull command[0m: [34m/opt/anaconda3/envs/py39/bin/python /opt/anaconda3/envs/py39/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/tmpifxdz7vp[0m
[1;35mcwd[0m: /private/var/folders/fs/p8dj3pds1c572m6bv554kn3c0000gn/T/pip-install-sb5zorwb/opencv-python_df8240dc6b5e41d0ac89ecfa36c3d7dc
[?25herror
[31m ERROR: Failed building wheel for opencv-python[0m[31m
[0mFailed to build opencv-python
[31mERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects[0m[31m
[0mNote: you may need to restart the kernel to use updated packages.