Jetson xavier nx opencv issue

if i run it on IDLE, it will run, but if i run it on the terminal print error message

Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:740 No cameras available
[ WARN:0] global /home/txgt/opencv/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (1081) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

please help me

What do you mean run it on IDLE?

Did you confirm the sensor driver loaded?

When I load a Python file in IDLE and press F5, the code runs, but when I try to execute it in the terminal window with python3 xx.py, the following error occurs.

Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:740 No cameras available
[ WARN:0] global /home/txgt/opencv/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (1081) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

Please confirm the camera driver by below commands.

v4l2-ctl --list-formats
nvargus_nvraw --lps

These are the results of commands executed in the terminal

Looks like argus recognize the camera.
Maybe check below code.


This is the result of running the above code.