Error when install torchvision on TX2

I have followed the instructions to install pytorch1.7.0, but when install torchvison, i met an error.

My environment is as follows:

Environment:
Jetson TX2
JetPack 4.4.1
Ubuntu18.04 LTS
python 3.6
pytorch 1.7.0

The process of installing pytorch:

$ wget https://nvidia.box.com/shared/static/wa34qwrwtk9njtyarwt5nvo6imenfy26.whl -O torch-1.7.0-cp36-cp36m-linux_aarch64.whl
$ sudo apt-get install python3-pip libopenblas-base libopenmpi-dev 
$ pip3 install Cython
$ pip3 install numpy torch-1.7.0-cp36-cp36m-linux_aarch64.whl

The error is as follows:

$ sudo apt-get install libjpeg-turbo8=1.4.2-0ubuntu3.4
$ sudo apt-get install libjpeg-dev zlib1g-dev
$ git clone --branch 0.8.1 https://github.com/pytorch/vision torchvision   
$ cd torchvision
$ export BUILD_VERSION=0.8.1
$ sudo python3 setup.py install
Building wheel torchvision-0.8.0a0+45f960c
PNG found: False
Running build on conda-build: False
Running build on conda: False
JPEG found: True
Building torchvision with JPEG image support
FFmpeg found: True
ffmpeg include path: /usr/include
ffmpeg library_dir: /usr/lib
running install
running bdist_egg
running egg_info
writing torchvision.egg-info/PKG-INFO
writing dependency_links to torchvision.egg-info/dependency_links.txt
writing requirements to torchvision.egg-info/requires.txt
writing top-level names to torchvision.egg-info/top_level.txt
reading manifest file 'torchvision.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
writing manifest file 'torchvision.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
copying torchvision/version.py -> build/lib.linux-aarch64-3.6/torchvision
running build_ext
building 'torchvision._C' extension
Emitting ninja build file /home/xgy/torchvision/build/temp.linux-aarch64-3.6/build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/8] c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/vision.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
[2/8] c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
[3/8] c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
[4/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/DeformConv_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/DeformConv_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[5/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/PSROIPool_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/PSROIPool_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[6/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/nms_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/nms_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[7/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/ROIAlign_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/ROIAlign_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[8/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/ROIPool_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/ROIPool_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
FAILED: c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/vision.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
/home/xgy/torchvision/torchvision/csrc/vision.cpp:1:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
FAILED: c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/Parallel.h:149:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/utils.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/cloneable.h:5,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/all.h:12,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:4,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp:1:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/ParallelOpenMP.h:84:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
 #pragma omp parallel for if ((end - begin) >= grain_size)
 
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/Device.h:3:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/python.h:8,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:6,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp:1:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
FAILED: c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/Parallel.h:149:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/utils.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/cloneable.h:5,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/all.h:12,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:4,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp:2:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/ParallelOpenMP.h:84:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
 #pragma omp parallel for if ((end - begin) >= grain_size)
 
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/Device.h:3:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/python.h:8,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:6,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp:2:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1522, in _run_ninja_build
    env=env)
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "setup.py", line 424, in <module>
    'clean': clean,
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/bdist_egg.py", line 167, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/bdist_egg.py", line 153, in call_command
    self.run_command(cmdname)
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/install_lib.py", line 11, in run
    self.build()
  File "/usr/lib/python3.6/distutils/command/install_lib.py", line 109, in build
    self.run_command('build_ext')
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 79, in run
    _build_ext.run(self)
  File "/home/xgy/.local/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 653, in build_extensions
    build_ext.build_extensions(self)
  File "/home/xgy/.local/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
    _build_ext.build_ext.build_extensions(self)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
    self._build_extensions_serial()
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
    self.build_extension(ext)
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 196, in build_extension
    _build_ext.build_extension(self, ext)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 482, in unix_wrap_ninja_compile
    with_cuda=with_cuda)
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1238, in _write_ninja_file_and_compile_objects
    error_prefix='Error compiling objects for extension')
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1538, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error compiling objects for extension

I don’t know how to solve. Hope your help. Thanks.

Hi @axuguanyu, can you try running sudo apt-get install libpython3-dev before you run the sudo python3 setup.py install step?

Thanks for your reply. I have followed your advice, but there is still an error.

$ sudo python3 setup.py install
Building wheel torchvision-0.8.0a0+45f960c
PNG found: False
Running build on conda-build: False
Running build on conda: False
JPEG found: True
Building torchvision with JPEG image support
FFmpeg found: True
ffmpeg include path: /usr/include
ffmpeg library_dir: /usr/lib
running install
running bdist_egg
running egg_info
writing torchvision.egg-info/PKG-INFO
writing dependency_links to torchvision.egg-info/dependency_links.txt
writing requirements to torchvision.egg-info/requires.txt
writing top-level names to torchvision.egg-info/top_level.txt
reading manifest file 'torchvision.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
writing manifest file 'torchvision.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
copying torchvision/version.py -> build/lib.linux-aarch64-3.6/torchvision
running build_ext
building 'torchvision._C' extension
Emitting ninja build file /home/xgy/torchvision/build/temp.linux-aarch64-3.6/build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/8] c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/vision.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
[2/8] c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
[3/8] c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
[4/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/DeformConv_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/DeformConv_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[5/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/PSROIPool_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/PSROIPool_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[6/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/nms_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/nms_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[7/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/ROIAlign_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/ROIAlign_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
[8/8] /usr/local/cuda/bin/nvcc -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cuda/ROIPool_cuda.cu -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cuda/ROIPool_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_62,code=sm_62 -std=c++14
FAILED: c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/vision.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/vision.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
/home/xgy/torchvision/torchvision/csrc/vision.cpp:1:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
FAILED: c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/Parallel.h:149:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/utils.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/cloneable.h:5,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/all.h:12,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:4,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp:2:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/ParallelOpenMP.h:84:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
 #pragma omp parallel for if ((end - begin) >= grain_size)
 
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/Device.h:3:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/python.h:8,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:6,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/ROIAlign_cpu.cpp:2:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
FAILED: c++ -MMD -MF /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o.d -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITH_CUDA -I/home/xgy/torchvision/torchvision/csrc -I/home/xgy/.local/lib/python3.6/site-packages/torch/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/TH -I/home/xgy/.local/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/usr/include/python3.6m -c -c /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp -o /home/xgy/torchvision/build/temp.linux-aarch64-3.6/home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/Parallel.h:149:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/utils.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/cloneable.h:5,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn.h:3,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/all.h:12,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:4,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp:1:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/ATen/ParallelOpenMP.h:84:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
 #pragma omp parallel for if ((end - begin) >= grain_size)
 
In file included from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/Device.h:3:0,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/python.h:8,
                 from /home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/extension.h:6,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/vision_cpu.h:2,
                 from /home/xgy/torchvision/torchvision/csrc/cpu/nms_cpu.cpp:1:
/home/xgy/.local/lib/python3.6/site-packages/torch/include/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1522, in _run_ninja_build
    env=env)
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "setup.py", line 424, in <module>
    'clean': clean,
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/bdist_egg.py", line 167, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/bdist_egg.py", line 153, in call_command
    self.run_command(cmdname)
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/install_lib.py", line 11, in run
    self.build()
  File "/usr/lib/python3.6/distutils/command/install_lib.py", line 109, in build
    self.run_command('build_ext')
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 79, in run
    _build_ext.run(self)
  File "/home/xgy/.local/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 653, in build_extensions
    build_ext.build_extensions(self)
  File "/home/xgy/.local/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
    _build_ext.build_ext.build_extensions(self)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
    self._build_extensions_serial()
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
    self.build_extension(ext)
  File "/home/xgy/.local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 196, in build_extension
    _build_ext.build_extension(self, ext)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 482, in unix_wrap_ninja_compile
    with_cuda=with_cuda)
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1238, in _write_ninja_file_and_compile_objects
    error_prefix='Error compiling objects for extension')
  File "/home/xgy/.local/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1538, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error compiling objects for extension

Hi @axuguanyu - sorry for the delay. Can you try running this too:

$ sudo apt-get install libpython3.6-dev

Then can you confirm that you can find Python.h found under /usr/include/python3.6m on your system?