Building onnxruntime on Jetson TX2 with python 3.7.8 and jetpack 4.4

I am trying to build it onnxruntime on Jetson TX2 with python 3.7.8 and jetpack 4.4. While the build was successful, I ran into the following issue while importing it

Python 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:52)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import onnxruntime
/home/qureai/.local/lib/python3.7/site-packages/onnxruntime/capi/_pybind_state.py:14: UserWarning: Cannot load onnxruntime.capi. Error: 'Python version mismatch: module was compiled for Python 3.6, but the interpreter version is incompatible: 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:52)
[GCC 7.5.0].'.
  warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'.".format(str(e)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/qureai/.local/lib/python3.7/site-packages/onnxruntime/__init__.py", line 13, in <module>
    from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, set_seed, \
ImportError: cannot import name 'get_all_providers' from 'onnxruntime.capi._pybind_state' (/home/qureai/.local/lib/python3.7/site-packages/onnxruntime/capi/_pybind_state.py)

I was able to build onnxruntime on the same board with python 3.6.9 and it ran successfully.

System information

  • OS Platform and Distribution
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic
NVIDIA Jetson TX2 - Jetpack 4.4 [L4T 32.4.3]                                                                                                       - Version: 3.0.1                 
 - Jetpack:        4.4 [L4T 32.4.3]                      
 - Board:                                                                                                                                          
   * Type:           TX2                                                                 
   * SOC Family:     tegra186     ID: 24                                                      
   * Module:         P3310-1000   Board: UNKNOWN                                              
   * Code Name:      quill                                                                    
   * Cuda ARCH:      6.2                                                          
   * Board ids:      3310:0000:A0                                                                                                                                                                                                             
 - Libraries:                                           
   * CUDA:         10.2.89                                          
   * OpenCV:       4.1.1  compiled CUDA: NO                     
   * TensorRT:     7.1.3.0                                        
   * VPI:          0.3.7                                                                      
   * VisionWorks:  1.6.0.501                                                                  
   * Vulkan:       1.2.70                                                                     
   * cuDNN:        8.0.0.180                                                                                                                                                     
  • ONNX Runtime installed from : Source
  • ONNX Runtime version:
  • Python version: 3.7.8
  • GCC/Compiler version (if compiling from source): gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
  • CUDA/cuDNN version: 10.2.89/ 8.0.0.180

To Reproduce

I have built onnxruntime for python 3.6 using the instructions here

To build it for python3.7, I installed miniforge from here and created a python3.7 environment

# remove line 895,896 in https://github.com/microsoft/onnxruntime/blob/master/cmake/CMakeLists.txt
        - string (APPEND CMAKE_CUDA_FLAGS "-gencode=arch=compute_53,code=sm_53 -gencode=arch=compute_62,code=sm_62") #nano, TX1, TX2 
        - string (APPEND CMAKE_CUDA_FLAGS "-gencode=arch=compute_72,code=sm_72") # Jetson N
        + string (APPEND CMAKE_CUDA_FLAGS "-gencode=arch=compute_62,code=sm_62") # 62 for tx2
$ ./build.sh --update --config Release --build --build_wheel \
   --use_cuda --cuda_home /usr/local/cuda --cudnn_home /usr/lib/aarch64-linux-gnu

Expected behavior
Build will be successful and a wheel file will be created. When you install the wheel file and import onnxruntime, you’ll encounter this error

[GCC 7.5.0].'.
  warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'.".format(str(e)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/qureai/.local/lib/python3.7/site-packages/onnxruntime/__init__.py", line 13, in <module>
    from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, set_seed, \
ImportError: cannot import name 'get_all_providers' from 'onnxruntime.capi._pybind_state' (/home/qureai/.local/lib/python3.7/site-packages/onnxruntime/capi/_pybind_state.py)

I think the problem may be with pybind11 which is somehow picking python3.6 instead of 3.7.

cmake output

[ 97%] Built target onnxruntime_test_all                                                                                                                                                                                                      
[ 97%] Performing update step for 'pybind11'                                                                                                                                                                                                  
[ 97%] No patch step for 'pybind11'                                                                                                                                                                                                           
[ 97%] No configure step for 'pybind11'                                                                                                                                                                                                       
[ 97%] No build step for 'pybind11'                                                                                                                                                                                                           
[ 97%] No install step for 'pybind11'                                                                                                                                                                                                         
[ 97%] Completed 'pybind11'                                                                                                                                                                                                                   
[ 98%] Built target pybind11                                                                                                                                                                                                                  
[100%] Built target onnxruntime_pybind11_state 

Hi,

Sorry that python3.7 is not official supported in our OS.

This may cause lots of dependencies since the package installed from pre-built may not have python3.7 support.
It’s recommended to check if the required package for onnxruntime do have support for v3.7 first.

Thanks.