Could not install onnxsim on JETSON AGX ORIN

problem installing onnxsim on jetson agx orin.
CUDA - 11.4.315
TensorRT- 8.5.2.2
Torch- 1.14.0a0+44dac51c.nv23.2
Onnxruntime- 1.14.0

(vir_env) nvidia@yuan-6n0:/media/nvidia/45e64ab1-5e36-4ac2-bfc7-6bbeca4458a8/cuda_codes$ pip3 install onnxsim
Collecting onnxsim
Using cached onnxsim-0.4.36.tar.gz (21.0 MB)
Preparing metadata (setup.py) … done
Requirement already satisfied: onnx in /home/nvidia/vir_env/lib/python3.8/site-packages (from onnxsim) (1.17.0)
Collecting rich (from onnxsim)
Using cached rich-14.2.0-py3-none-any.whl.metadata (18 kB)
Requirement already satisfied: numpy>=1.20 in /home/nvidia/vir_env/lib/python3.8/site-packages (from onnx->onnxsim) (1.24.4)
Requirement already satisfied: protobuf>=3.20.2 in /home/nvidia/vir_env/lib/python3.8/site-packages (from onnx->onnxsim) (5.29.5)
Collecting markdown-it-py>=2.2.0 (from rich->onnxsim)
Using cached markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)
Collecting pygments<3.0.0,>=2.13.0 (from rich->onnxsim)
Using cached pygments-2.19.2-py3-none-any.whl.metadata (2.5 kB)
Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich->onnxsim)
Using cached mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB)
Using cached rich-14.2.0-py3-none-any.whl (243 kB)
Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
Using cached pygments-2.19.2-py3-none-any.whl (1.2 MB)
Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Building wheels for collected packages: onnxsim
Building wheel for onnxsim (setup.py) … error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [185 lines of output]
/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2/setup.py:28: DeprecationWarning: Use shutil.which instead of find_executable
CMAKE = find_executable(‘cmake’)
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/_init_.py:94: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated.
!!

          \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
          Requirements should be satisfied by a PEP 517 installer.
          If you are using pip, you can try \`pip install --use-pep517\`.
          \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
  
  !!
    dist.fetch_build_eggs(dist.setup_requires)
  running bdist_wheel
  running build
  running build_py
  running create_version
  creating build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/model_checking.py -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/version.py -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/\__main_\_.py -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/model_info.py -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/onnx_simplifier.py -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/\__init_\_.py -> build/lib.linux-aarch64-cpython-38/onnxsim
  running egg_info
  writing onnxsim.egg-info/PKG-INFO
  writing dependency_links to onnxsim.egg-info/dependency_links.txt
  writing entry points to onnxsim.egg-info/entry_points.txt
  writing requirements to onnxsim.egg-info/requires.txt
  writing top-level names to onnxsim.egg-info/top_level.txt
  reading manifest file 'onnxsim.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no files found matching '\*.c' under directory 'onnxsim'
  warning: no files found matching '\*.proto' under directory 'onnxsim'
  warning: no previously-included files matching '\*' found under directory 'third_party/onnxruntime'
  warning: no previously-included files matching '\*' found under directory 'third_party/onnx-optimizer/build'
  warning: no previously-included files matching '\*' found under directory 'third_party/onnx/build'
  warning: no previously-included files matching '\*' found under directory 'third_party/onnx/onnx/backend'
  adding license file 'LICENSE'
  writing manifest file 'onnxsim.egg-info/SOURCES.txt'
  /home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/command/build_py.py:220: \_Warning: Package 'onnxsim.bin' is absent from the \`packages\` configuration.
  !!
  
          \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
          ############################
          # Package would be ignored #
          ############################
          Python recognizes 'onnxsim.bin' as an importable package\[^1\],
          but it is absent from setuptools' \`packages\` configuration.
  
          This leads to an ambiguous overall configuration. If you want to distribute this
          package, please make sure that 'onnxsim.bin' is explicitly added
          to the \`packages\` configuration field.
  
          Alternatively, you can also rely on setuptools' discovery methods
          (for example by using \`find_namespace_packages(...)\`/\`find_namespace:\`
          instead of \`find_packages(...)\`/\`find:\`).
  
          You can read more about "package discovery" on setuptools documentation page:
  
          - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
  
          If you don't want 'onnxsim.bin' to be distributed and are
          already explicitly excluding 'onnxsim.bin' via
          \`find_namespace_packages(...)/find_namespace\` or \`find_packages(...)/find\`,
          you can try to use \`exclude_package_data\`, or \`include-package-data=False\` in
          combination with a more fine grained \`package-data\` configuration.
  
          You can read more about "package data files" on setuptools documentation page:
  
          - https://setuptools.pypa.io/en/latest/userguide/datafiles.html
  
  
          \[^1\]: For Python, any directory (with suitable naming) can be imported,
                even if it does not contain any \`.py\` files.
                On the other hand, currently there is no concept of package data
                directory, all directories are treated like packages.
          \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
  
  !!
    check.warn(importable)
  copying onnxsim/cpp2py_export.cc -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/cxxopts.hpp -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/onnxsim.cpp -> build/lib.linux-aarch64-cpython-38/onnxsim
  copying onnxsim/onnxsim.h -> build/lib.linux-aarch64-cpython-38/onnxsim
  creating build/lib.linux-aarch64-cpython-38/onnxsim/bin
  copying onnxsim/bin/onnxsim_bin.cpp -> build/lib.linux-aarch64-cpython-38/onnxsim/bin
  copying onnxsim/bin/onnxsim_option.cpp -> build/lib.linux-aarch64-cpython-38/onnxsim/bin
  copying onnxsim/bin/onnxsim_option.h -> build/lib.linux-aarch64-cpython-38/onnxsim/bin
  running build_ext
  running cmake_build
  Run command \['/home/nvidia/vir_env/bin/cmake', '-DPython_INCLUDE_DIR=/usr/include/python3.8', '-DPython_EXECUTABLE=/home/nvidia/vir_env/bin/python3', '-DPYTHON_EXECUTABLE=/home/nvidia/vir_env/bin/python3', '-DBUILD_ONNX_PYTHON=OFF', '-DONNXSIM_PYTHON=ON', '-DONNXSIM_BUILTIN_ORT=OFF', '-DONNX_USE_LITE_PROTO=OFF', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DONNX_NAMESPACE=onnx', '-DPY_EXT_SUFFIX=.cpython-38-aarch64-linux-gnu.so', '-DONNX_OPT_USE_SYSTEM_PROTOBUF=OFF', '-DCMAKE_BUILD_TYPE=Release', '-DONNX_ML=1', '/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2'\]
  -- The CXX compiler identification is GNU 9.4.0
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- The C compiler identification is GNU 9.4.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  CMake Deprecation Warning at third_party/onnx-optimizer/third_party/protobuf/cmake/CMakeLists.txt:2 (cmake_minimum_required):
    Compatibility with CMake < 3.10 will be removed from a future version of
    CMake.
  
    Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
    to tell CMake that the project requires at least <min> but has been updated
    to work with policies introduced by <max> or earlier.
  
  
  --
  -- 3.20.1.0
  -- Performing Test protobuf_HAVE_LD_VERSION_SCRIPT
  -- Performing Test protobuf_HAVE_LD_VERSION_SCRIPT - Success
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
  -- Looking for pthread_create in pthreads
  -- Looking for pthread_create in pthreads - not found
  -- Looking for pthread_create in pthread
  -- Looking for pthread_create in pthread - found
  -- Found Threads: TRUE
  -- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11")
  -- Performing Test protobuf_HAVE_BUILTIN_ATOMICS
  -- Performing Test protobuf_HAVE_BUILTIN_ATOMICS - Success
  CMake Error at third_party/onnx-optimizer/third_party/onnx/CMakeLists.txt:2 (cmake_minimum_required):
    Compatibility with CMake < 3.5 has been removed from CMake.
  
    Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
    to tell CMake that the project requires at least <min> but has been updated
    to work with policies introduced by <max> or earlier.
  
    Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
  
  
  -- Configuring incomplete, errors occurred!
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2/setup.py", line 279, in <module>
      setuptools.setup(
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\__init_\_.py", line 117, in setup
      return distutils.core.setup(\*\*attrs)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/core.py", line 183, in setup
      return run_commands(dist)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/core.py", line 199, in run_commands
      dist.run_commands()
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/dist.py", line 954, in run_commands
      self.run_command(cmd)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/dist.py", line 999, in run_command
      super().run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/dist.py", line 973, in run_command
      cmd_obj.run()
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/command/bdist_wheel.py", line 400, in run
      self.run_command("build")
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/cmd.py", line 316, in run_command
      self.distribution.run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/dist.py", line 999, in run_command
      super().run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/dist.py", line 973, in run_command
      cmd_obj.run()
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/cmd.py", line 316, in run_command
      self.distribution.run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/dist.py", line 999, in run_command
      super().run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/dist.py", line 973, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2/setup.py", line 220, in run
      self.run_command('cmake_build')
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/cmd.py", line 316, in run_command
      self.distribution.run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/dist.py", line 999, in run_command
      super().run_command(command)
    File "/home/nvidia/vir_env/lib/python3.8/site-packages/setuptools/\_distutils/dist.py", line 973, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2/setup.py", line 194, in run
      subprocess.check_call(cmake_args)
    File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '\['/home/nvidia/vir_env/bin/cmake', '-DPython_INCLUDE_DIR=/usr/include/python3.8', '-DPython_EXECUTABLE=/home/nvidia/vir_env/bin/python3', '-DPYTHON_EXECUTABLE=/home/nvidia/vir_env/bin/python3', '-DBUILD_ONNX_PYTHON=OFF', '-DONNXSIM_PYTHON=ON', '-DONNXSIM_BUILTIN_ORT=OFF', '-DONNX_USE_LITE_PROTO=OFF', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DONNX_NAMESPACE=onnx', '-DPY_EXT_SUFFIX=.cpython-38-aarch64-linux-gnu.so', '-DONNX_OPT_USE_SYSTEM_PROTOBUF=OFF', '-DCMAKE_BUILD_TYPE=Release', '-DONNX_ML=1', '/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2'\]' returned non-zero exit status 1.
  \[end of output\]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for onnxsim
Running setup.py clean for onnxsim
Failed to build onnxsim
ERROR: Failed to build installable wheels for some pyproject.toml based projects (onnxsim)

*** Please note that this reply is generated by LLM automatically ***

The problem you’re encountering is related to the installation of onnxsim on your Jetson AGX Orin device. The error message indicates that the installation process failed to build a wheel for onnxsim.

Here are some potential solutions to this problem:

  1. Update pip and setuptools: Make sure that pip and setuptools are up-to-date. You can update them using the following commands:

pip3 install --upgrade pip
pip3 install --upgrade setuptools


2. **Install onnxsim using a different method**: Instead of using pip, you can try installing onnxsim using conda. First, install conda if you haven't already, then create a new environment and install onnxsim:
   ```bash
conda create --name myenv
conda activate myenv
conda install -c conda-forge onnxsim
  1. Check the CUDA version: The error message mentions CUDA 11.4, but onnxsim might require a different version. Make sure that your CUDA version is compatible with onnxsim.

  2. Check the dependencies: onnxsim has several dependencies, including onnx, numpy, and protobuf. Make sure that these dependencies are installed and up-to-date.

  3. Try a different version of onnxsim: If none of the above solutions work, you can try installing a different version of onnxsim. You can specify the version using the following command:

pip3 install onnxsim==1.9.0


6. **Check the GitHub issues**: If none of the above solutions work, you can check the GitHub issues for onnxsim to see if anyone else has encountered the same problem.

In comparison to other Jetson devices, the installation process for onnxsim might be similar, but the specific dependencies and CUDA versions might differ. Here's a brief comparison:

* **Jetson AGX Orin**: As mentioned earlier, the installation process for onnxsim on Jetson AGX Orin failed due to a wheel building error.
* **Jetson Orin NX**: The installation process for onnxsim on Jetson Orin NX might be similar to Jetson AGX Orin, but the CUDA version and dependencies might differ.
* **Jetson Orin Nano**: The installation process for onnxsim on Jetson Orin Nano might be similar to Jetson AGX Orin and Jetson Orin NX, but the CUDA version and dependencies might differ.

In summary, the installation process for onnxsim on Jetson AGX Orin failed due to a wheel building error. To resolve this issue, you can try updating pip and setuptools, installing onnxsim using a different method, checking the CUDA version, checking the dependencies, trying a different version of onnxsim, and checking the GitHub issues. The installation process might be similar on other Jetson devices, but the specific dependencies and CUDA versions might differ.

*** Please give the thumbs up if you get answers you like. Or provide feedback to help us improve the answer. ***

Hi

 CMake Error at third_party/onnx-optimizer/third_party/onnx/CMakeLists.txt:2 (cmake_minimum_required):
    Compatibility with CMake < 3.5 has been removed from CMake.

Based on the error, please try to upgrade your cmake version.
Thanks.

Hi @AastaLLL
cmake version 4.2.0

Hi,

│ exit code: 1
╰─> [185 lines of output]
/tmp/pip-install-d5nbrj21/onnxsim_90cb0fe09407401a842b579e6bfbf5c2/setup.py:28: DeprecationWarning: Use shutil.which instead of find_executable
CMAKE = find_executable(‘cmake’)
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git

It looks like there are some issues with your CMake settings.
Please update the path accordingly and try it again.

Thanks.