How to install opencv-python for python3.6

Oh yeah, forgot to mention the swapfile:

Almost the same sequence of commands from “air1kdf” above. just the first command I used was different:
sudo fallocate -l 4.0G /swapfile # this is the difference sudo chmod 600 /swapfile
sudo mkswap /swapfile sudo swapon /swapfile

Also, to make the swapfile activated during reboot, edit /etc/fstab:
$ sudo nano /etc/fstab

And add the following line:
/swapfile none swap 0 0

Save it and it should activate the swapfile after your next reboot.

Although marked as “solved”, it really isn’t.
OpenCV4.1 IS available loaded with Jetpack 4.3. out of the box, but it does not appear as the “opencv-python” module, so it is not recognized as available by other packages such as stable-baselines. If you do a apt-install opencv you get version 3.2 and it appears as the module " python3-opencv" which is also not recognized by loading packages as OpenCV.
How can we get the pre-loaded OpenCV4.1 to appear as the requested module “opencv-python”?

is there any real and working answer to this? i need opencv-contrib package to use object trackers.

edit: the answer is “build it yourself”. given script does not exist any more. this link will help you:

go to step 14 and follow the instructions. I didn’t use virtual environment. it will take around 3 hours.

You may try the script by community member @mdegans: https://github.com/mdegans/nano_build_opencv

Thanks @dkreutz

There are also pre-built docker images for JetPack 4.3 and 4.4 you can use as a base image:
https://hub.docker.com/r/mdegans/tegra-opencv/tags

That’ll save you a few hours of waiting for the script to build and is probably eaiser to test, deploy, and far more repeatable than the script itself. Make sure to use the --runtime nvidia flag to access the GPU or it’ll segfault when you try to “import cv2” or equivalent. Just:

sudo docker run --user $(id -u):$(cut -d: -f3 < <(getent group video)) --runtime nvidia -it --rm mdegans/tegra-opencv:latest

The --user bit is optional but recommended to avoid running the container as root.

And you can then:

 $ sudo docker run --user $(id -u):$(cut -d: -f3 < <(getent group video)) --runtime nvidia -it --rm mdegans/tegra-opencv:latest
[sudo] password for your_username_here: 
Unable to find image 'mdegans/tegra-opencv:latest' locally
latest: Pulling from mdegans/tegra-opencv
3b5e2c02f523: Already exists 
b9448035bb0a: Already exists 
ec9ea6732d09: Already exists 
515b0d7ffbf7: Already exists 
7663c88dd173: Already exists 
5dd4bd16e931: Already exists 
5231bd433c70: Already exists 
9e017cdad796: Already exists 
0c8ba4b0f40b: Already exists 
de2653fc4eda: Already exists 
21b3dc12ac76: Already exists 
18d3041d2711: Already exists 
8b4bed079038: Already exists 
efb313fc2a73: Already exists 
5c1e867b3d6d: Already exists 
aee12882d462: Pull complete 
c8c16c286602: Pull complete 
eacb1135637c: Pull complete 
92fdb5579a06: Pull complete 
4d54fa5df78f: Pull complete 
46d431fc04e0: Pull complete 
Digest: sha256:379826dbe07d5135615e02de0efc62da59ddb6097ca98e639f971db907b96776
Status: Downloaded newer image for mdegans/tegra-opencv:latest
I have no name!@e71c4e768a02:/usr/local/src/build_opencv$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.cuda.printCudaDeviceInfo(0) 
*** CUDA Device Query (Runtime API) version (CUDART static linking) *** 

Device count: 1

Device 0: "Xavier"
  CUDA Driver Version / Runtime Version          10.20 / 10.20
  CUDA Capability Major/Minor version number:    7.2
  Total amount of global memory:                 15823 MBytes (16591372288 bytes)
  GPU Clock Speed:                               1.38 GHz
  Max Texture Dimension Size (x,y,z)             1D=(131072), 2D=(131072,65536), 3D=(16384,16384,16384)
  Max Layered Texture Size (dim) x layers        1D=(32768) x 2048, 2D=(32768,32768) x 2048
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     2147483647 x 65535 x 65535
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and execution:                 Yes with 1 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            Yes
  Support host page-locked memory mapping:       Yes
  Concurrent kernel execution:                   Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support enabled:                No
  Device is using TCC driver mode:               No
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           0 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) 

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 10.20, CUDA Runtime Version = 10.20, NumDevs = 1

If you’re still on jetpack 4.3, you can use jp-r32.3.1-cv-4.3.0 instead of latest as a tag.

Can you also import opencv_contrib packages like aruco?