Problem installing on Jetson Nano - AttributeError: module 'cv2' has no attribute '__version__'

Hi - I have been trying to install cv2 with cuda support on a jetson nano using this guide:

It installs for both python 2 and 3 but in python 3 while I can import cv2 it does not seem to be picking up the opencv_contrib modules as per below:

Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute '__version__'

Python 2 works fine:

Python 2.7.17 (default, Feb 27 2021, 15:10:58) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.2'
>>>

My make config (I had to add last 3 options as it wasn’t picking up python3 libraries):

cmake
-D CMAKE_BUILD_TYPE=RELEASE
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules
-D CMAKE_INSTALL_PREFIX=/usr
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3
-D WITH_OPENCL=OFF
-D WITH_CUDA=ON
-D CUDA_ARCH_BIN=5.3
-D CUDA_ARCH_PTX=""
-D WITH_CUDNN=ON
-D WITH_CUBLAS=ON
-D ENABLE_FAST_MATH=ON
-D CUDA_FAST_MATH=ON
-D OPENCV_DNN_CUDA=ON
-D ENABLE_NEON=ON
-D WITH_QT=ON
-D WITH_OPENMP=ON
-D WITH_OPENGL=ON
-D BUILD_TIFF=ON
-D WITH_FFMPEG=ON
-D WITH_GSTREAMER=ON
-D WITH_TBB=ON
-D BUILD_TBB=ON
-D BUILD_TESTS=OFF
-D WITH_EIGEN=ON
-D WITH_V4L=ON
-D WITH_LIBV4L=ON
-D OPENCV_ENABLE_NONFREE=ON
-D INSTALL_C _EXAMPLES=OFF
-D INSTALL_PYTHON_EXAMPLES=OFF
-D BUILD_opencv_python3=TRUE
-D OPENCV_GENERATE_PKGCONFIG=ON
-D BUILD_EXAMPLES=OFF
-D PYTHON3_INCLUDE_DIR2:PATH=/usr/include/aarch64-linux-gnu/python3.6m/
-D PYTHON3_LIBRARY:FILEPATH=/usr/lib/aarch64-linux-gnu/libpython3.6m.so
-D PYTHON3_NUMPY_INCLUDE_DIRS:PATH=/usr/local/lib/python3.6/dist-packages/numpy/core/include

I’ve been banging my head against a wall with this for a couple of days now so any help gratefully received - thanks!

it might be a python 2/3 problem, iirc, you have to use

cv2.__version__

in python3

(ps. i corrected your question title (removed the underscores) so it matches the error, hope it’s alright)

Thanks - I thought I had included the underscores in the post as the issue I;m having is WITH the underscoresL

>>> cv2.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute '__version__'
>>> quit()

OK - the formatting on the forum is removing them: not sure how to escape them sop they appear?

i’m getting same error as above without underscores, and it works with them, so call me confused, now ;(

(opencv 4.5.2-pre, python 3.8)

[edit}, ok, i changed above formatting (mark w. mouse, press shift-ctrl-c) also undo title changes

My problem is only with underscores, I’m posting the code with underscores but they are being removed by the site so the original title was correct.

1 Like

ok, sorry for the confusion :wink:

No worries, thanks for sorting the underscores out!

if cv2.__version__ doesn’t exist, your installation of OpenCV’s python module is broken.

you said you built it yourself… how did you install opencv’s python module into your python installation?