Error I get when using python3.6
>>> import cv2
Traceback (most recent call last):
File "", line 1, in
ImportError: /usr/local/lib/python3.6/dist-packages/cv2.so: undefined symbol: PyCObject_Type
However, when I use python2.7, I get no errors
>>> import cv2
>>> cv2.__version__
'4.0.0'
I installed opencv 4.0.0 from source and ensured proper bindings to Python2.7 and Python3.6. Ensured that ..../dist-packages for both versions of python had cv2.so file. See contents of dis-packages below.
$ls /usr/local/lib/python2.7/dist-packages
cv2.so
$ ls /usr/local/lib/python3.6/dist-packages
clonevirtualenv.py pip-20.2.1.dist-info
cv2.so py
decorator-4.4.0.dist-info py-1.8.0.dist-info
decorator.py __pycache__
future pykalman
future-0.17.1.dist-info pykalman-0.9.5.dist-info
importlib_metadata stevedore
importlib_metadata-1.7.0.dist-info stevedore-3.2.0.dist-info
libfuturize virtualenv-16.6.0.dist-info
libpasteurize virtualenv_clone-0.5.4.dist-info
networkx virtualenv.py
networkx-2.3.dist-info virtualenv_support
numpy virtualenvwrapper
numpy-1.19.1.dist-info virtualenvwrapper-4.8.4.dist-info
numpy.libs virtualenvwrapper-4.8.4-nspkg.pth
past zipp-3.1.0.dist-info
pip zipp.py
SO, I see that cv2.so file is there in both dist-packages... I am not sure why I am seeing the error for Python3.6.
PS: The cv2.so file was initially missing from dis-packages of python3.6 when I checked after successful completion of cmake and make... So, I manually copied the cv2.so file from dist-packages of python2.7 and pasted it in dist-packages of oython3.6.. (I am not sure if this was the right thing to do!) SO, the file cv2.so is essentially the same in both versions of python.
Below is how i built from source.
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D PYTHON3_EXECUTABLE=$(which python3.6) \
-D PYTHON2_EXECUTABLE=$(which python2.7) \
-D PYTHON2_INCLUDE_DIR=$(python2.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON2_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/python2.7 \
-D PYTHON3_INCLUDE_DIR=$(python3.6 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/python3.6m \
-D PYTHON2_LIBRARY=/usr/lib/python2.7/config-aarch64-linux-gnu/libpython2.7.so \
-D PYTHON3_LIBRARY=/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu/libpython3.6.so \
-D PYTHON2_NUMPY_INCLUDE_DIR=$(python2.7 -c "import numpy; print(numpy.get_include())") \
-D PYTHON3_NUMPY_INCLUDE_DIR=$(python3 -c "import numpy; print(numpy.get_include())") \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=ON \
-D HAVE_opencv_python2=ON \
-D HAVE_opencv_python3=ON \
-D PYTHON_DEFAULT_EXECUTABLE=$(which python2.7) \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_PYTHON_SUPPORT=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=/usr/src/app \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D PYTHON3_CVPY_SUFFIX=.cpython-36m-aarch64-linux-gnu.so \
-D WITH_CUDA=OFF \
-D WITH_TBB=ON \
-D OPENCV_SKIP_PYTHON_LOADER=ON \
-D BUILD_opencv_hdf=OFF \
-D BUILD_EXAMPLES=ON ..
↧