Error compiling Torchvision 0.16.2 for Pytorch version 0.2.1 against Python3.9 on Jetpack 5.1.2


I followed the steps as per below link to build torchvision against python 3.9 on my Jetpack 5.1.2:

**$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev**
**$ git clone --branch v0.16.2 torchvision   # see below for version of torchvision to download**
**$ cd torchvision**
**$ export BUILD_VERSION=0.16.2  # where 0.x.0 is the torchvision version  **
**$ python3.9 install --user**
**$ cd ../  # attempting to load torchvision from build dir will result in import error**

But I am getting below error when I import “torchvision” after installing it.

root@linux:/home/cabs-willet/Downloads/torchvision# pip show torchvision
Name: torchvision
Version: 0.16.2
Summary: image and video datasets and models for torch deep learning
Home-page: GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision
Author: PyTorch Core Team
License: BSD
Location: /root/.local/lib/python3.9/site-packages/torchvision-0.16.2-py3.9-linux-aarch64.egg
Requires: numpy, pillow, requests, torch
root@linux:/home/cabs-willet/Downloads/torchvision# python3
Python 3.9.5 (default, Nov 23 2021, 15:27:38)
[GCC 9.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import torchvision
Traceback (most recent call last):
File “”, line 1, in
File “/home/cabs-willet/Downloads/torchvision/torchvision/”, line 6, in
from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils
File “/home/cabs-willet/Downloads/torchvision/torchvision/datasets/”, line 1, in
from ._optical_flow import FlyingChairs, FlyingThings3D, HD1K, KittiFlow, Sintel
File “/home/cabs-willet/Downloads/torchvision/torchvision/datasets/”, line 10, in
from PIL import Image
File “/usr/lib/python3/dist-packages/PIL/”, line 69, in
from . import _imaging as core
ImportError: cannot import name ‘_imaging’ from ‘PIL’ (/usr/lib/python3/dist-packages/PIL/

Please let me know how to fix this issue.


The error indicates a missing library(pillow).
Have you installed it for Python3.9?


Yes. After installing pillow for python 3.9 with the below command, installation was fully complete and successful.

$python3.9 -m pip install --user --upgrade Pillow

One more query:
Please reply to the below thread about Tensor flow source code build steps for Python 3.9 and pytorch 2.1.0.


Could you try to import it with Python 3.9 to confirm?

from PIL import Image


I tried importing" import torchvision". It did not throw any error.

Please provide me or point me to some steps, where Tensor flow can be built from source for python3.9.


Do you mean you have fixed the TorchVision issue?

For the TensorFlow building process, please follow the document below:


Yes. With the installation of Pillow with the below command, I was able to fix the Torchvision error issue while importing.

$python3.9 -m pip install --user --upgrade Pillow

Thanks for this link. However, I was already able to see a already prebuilt wheel file for tensorflow for Linux basedArm64) in the below link. I was able to successfully install this wheel file and install Tensor Flow.

Please confirm, if this is fine.

Could you please reply to this query of tensorflow in this link below