How to select opencv 4.0.0 version in python3 instead of 3.2.0 version


I have successfully build and compiled opencv using this script

If I do opencv_version it shows me 4.0.0 but if I check the version from the python3, it still shows older version 3.2.0. How do I make 4.0.0 versoion as default.

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__

You might try my script here instead. It’s been tested to build on a freshly flashed nano Image and in theory installs any version of OpenCV available in git. Both Python 2 and 3 support are enabled in the build.

To build version 4.0.0:

git clone
cd nano_build_opencv
./ 4.0.0

You can replace 4.0.0 with 4.1.0 if you want (or any git branch/tag). To help ensure a successful build you may wish to build without the graphical environment running on the nano. To temporarily do this, ssh into the nano, run sudo systemctl isolate, and then start the build as shown above. 4.0.0 has not been tested to build, but it should. 4.1.0 has been tested to build.

Hi mdegans

I think previously I didnt added swap on my nano and may be because of this it was showing some error.
This time I added swap and the script worked fine. Although it took 6-7 hrs for the complete setup but yes after its done, I can see the latest version of opencv in python3.


For me, when building with make -j3 it was fine until it was time to link and test, at which point it would hit a wall swapping and fail when swap ran out. If you do add a swap file or partition, I’d recommend doing it via a reliable, fast, external ssd.

Swap works by treating disk as ram, and when you’re moving things back and forth constantly as happens in a build, that translates into a lot of flash wear. If you swap off the sdcard, not only is it slow, it’s likely to wear the card down faster than more modern ssd designs, especially Optane. One of these in an external nvme enclosure, attached via USB3, should be much closer to having 16 or 32 more GB of ram on your nano (than a micro-sd ever will). Optane is usually normally used to cache ssds, but you can use it like this as well and it should work fine, though the second generation may not.

Of course, if you want to build faster than that, please see this thread for instructions on how to set up cross compilation.

Hey mdegans,

i used your script, but unfortunately it still shows me Version 3.2.0 instead of 4.0.0.
Do you have a hot tip for me?


In my experience, I have found the read IO speeds of uSD on Jetson nano (84.63 MB/Sec) to be faster than a USB3 flashdrive (31.02 MB/Sec). Could you cross-check the IO speeds you are seeing on Optane and let us know ?

I measureed the read speeds of both the devices via

hdparm -t <device>

more details on how it compares across platform and storage types are here:

If you’re using a very slow flash drive, then yes, it might be worse. I was suggesting a nvme or sata ssd attached via usb3 (specifically, Optane is probably the best for this). That should be much faster than a microsd.

Linked Medium post simply says “except for Jetson Nano” I’m not sure what that means. I just tried with a Samsung Evo 860 sata in a usb3 enclosure and got a respectable…

test@test-nano:/$ sudo hdparm -t /dev/sda

 Timing buffered disk reads: 874 MB in  3.00 seconds = 290.91 MB/sec

Dude was testing with I dunno what. I just re-ran it and got nearly identical results. Maybe he was using a usb-2 cable or something silly like that.

Can you post the results of this command run on the nano, please:

ls -lR /usr/local/lib/python3.6/dist-packages/

I am not using a slow flash drive. The same flash-drive is able to get 120 - 130 MB/Sec on multiple other systems (see the table here -, but on Jetson nano it is giving me only 31 MB/Sec. So the IO speed limitation is not with the drive but with Jetson Nano.

Has somebody from Nvidia or yourself benchmarked the max IO speed achievable via USB3 port ?

I am well aware of SATA SSDs, M2 NVMEs, Optane etc … Can you let us know the IO speeds you are seeing ?

I don’t know what to tell you. I just ran a benchmark (see my edited post). Given the drive is capable of faster than that, it’s probably about the limit. Then again i’ve never benchmarked that specific enclosure (that drive is used for a Wii U via usb2, so idrc), It is certainly capable of faster than you claim, however.

You know it’s possible if some of the pins are damaged on your usb-3 flash drive or the nano and it could be defaulting to usb2. 31MB/sec is about the limit of usb 2.0.

291 MB/Sec looks like decent number. I will try to replicate that at my end (but even if I cannot … I wouldn’t assume that you are silly or you are lying or anything like that … I will perhaps ask which is your USB to SATA adapter or something like that).

I had a couple of other USB devices on other USB ports (WiFi dongle and kbd/mouse dongle). But they were mostly idle, so I dont think that should create too much of a problem

I dont like the comment you made above (something silly like that ). Note that we are discussing and cross-checking facts and numbers here … a little more decent tone would be conductive of a proper discussion. Note that I am not questioning your credibility or technical acumen here. I was just asking you the numbers you are seeing and I am just documenting the numbers I have seen. Thats how technical people operate.

There is no cable involved, it was just a 128 GB USB 3.1 thumbdrive. The same thumb-drive was profiled on all the systems ( .

It’s nothing fancy and it has stickers all over it so I couldn’t tell you the brand, but it’s a sata to usb-c 3.0 enclosure and from that I have a usb 3.0 a->c cable going to the nano. Drive inside is an Evo 860 sata.

Can you post the results of a lsusb -vvv with the flash drive plugged into the nano please?

Sorry. I meant no offense by “silly”. I do “silly” things multiple times a day. There would be no need for testing if software engineers were perfect.

I am able to get decent speeds(260 MB/Sec) from SATA disk via a USB to SATA adapter. Thanks @mdegans for letting me know your IO speeds.

(env3) jithu@nano:~/master/003tawnk/d3$ sudo hdparm -t /dev/sda

 Timing buffered disk reads: 790 MB in  3.00 seconds = 263.18 MB/sec
(env3) jithu@nano:~/master/003tawnk/d3$ sudo hdparm -t /dev/sda

 Timing buffered disk reads: 796 MB in  3.00 seconds = 265.07 MB/sec
(env3) jithu@nano:~/master/003tawnk/d3$ sudo hdparm -t /dev/sda

 Timing buffered disk reads: 792 MB in  3.00 seconds = 263.60 MB/sec
(env3) jithu@nano:~/master/003tawnk/d3$

Yw. Strange that it didn’t work with your USB 3 flash drive. If you find it in lsusb -vvv it’ll tell you all about device and host capabilities.

Something is wrong if it’s not working at full speed. I will test tomorrow with some random USB 3 mass storage devices (flash readers, sticks, etc).

lsusb doesnt throw up anything interesting — just a few device descriptors. Again givess me 60 MB/Sec only consistently.

Shown below is the relevant portion of lsub output corresponding to the thumdrive:

Bus 002 Device 009: ID 0781:5583 SanDisk Corp. 
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         9
  idVendor           0x0781 SanDisk Corp.
  idProduct          0x5583 
  bcdDevice            1.00
  iManufacturer           1 
  iProduct                2 
  iSerial                 3 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           44
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              224mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst              15


FWIW the same SATA to USB adapter (with the same SSD) gives double the speed on a x86 laptop though

(env3) jithu@jjdelltouch:~/master/003tawnk$ sudo hdparm -t /dev/sdb

 Timing buffered disk reads: 1242 MB in  3.00 seconds = 413.69 MB/sec
(env3) jithu@jjdelltouch:~/master/003tawnk$ sudo hdparm -t /dev/sdb

 Timing buffered disk reads: 1242 MB in  3.00 seconds = 413.45 MB/sec
(env3) jithu@jjdelltouch:~/master/003tawnk$

Note that Jetson nano was giving only 260 MB/Sec

Welp. It says it’s connected via usb3. Strange the performance is lower for that one disk :/

I will run some tests tomorrow and see if I can replicate.

Yeah. I noticed the speed is about half of the drive’s full speed. I think that may be a limitation of how much bandwith the USB 3 bus has on Nano. I think I recall reading in the documentation somewhere something about that. That speed limit would still not explain why your device doesn’t operate at the full 120 (as it’s less than 250)… Or maybe it does. It’s a puzzlement.