pytorch & torchvision installation issue

Installed pyTorch & torchvision using following code:

wget -O torch-1.3.0-cp36-cp36m-linux_aarch64.whl
pip3 install numpy torch-1.3.0-cp36-cp36m-linux_aarch64.whl

git clone
cd vision && python3 install

I get below error when I import Torch and TorchVision. Does anyone know how to fix this? Thanks.

admin@jetson-nano:~$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch as t
>>> import torchvision as tv
 File "/usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/", line 3, in <module>
    from torchvision import models
  File "/usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/", line 12, in <module>
    from . import detection
  File "/usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/detection/", line 1, in <module>
    from .faster_rcnn import *
  File "/usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/detection/", line 13, in <module>
    from .rpn import AnchorGenerator, RPNHead, RegionProposalNetwork
  File "/usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/detection/", line 11, in <module>
    from . import _utils as det_utils
  File "/usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/detection/", line 19, in <module>
    class BalancedPositiveNegativeSampler(object):
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/", line 1219, in script
    _compile_and_register_class(obj, _rcb, qualified_name)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/", line 1076, in _compile_and_register_class
    _jit_script_class_compile(qualified_name, ast, rcb)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/", line 222, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/", line 1226, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
builtin cannot be used as a value:
at /usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/detection/
def zeros_like(tensor, dtype):
    # type: (Tensor, int) -> Tensor
    return torch.zeros_like(tensor, dtype=dtype, layout=tensor.layout,
                                                        ~~~~~~~~~~~~~ <--- HERE
                            device=tensor.device, pin_memory=tensor.is_pinned())
'zeros_like' is being compiled since it was called from '__torch__.torchvision.models.detection._utils.BalancedPositiveNegativeSampler.__call__'
at /usr/local/lib/python3.6/dist-packages/torchvision-0.5.0a0+300019d-py3.6-linux-aarch64.egg/torchvision/models/detection/

            # randomly select positive and negative examples
            perm1 = torch.randperm(positive.numel(), device=positive.device)[:num_pos]
            perm2 = torch.randperm(negative.numel(), device=negative.device)[:num_neg]

            pos_idx_per_image = positive[perm1]
            neg_idx_per_image = negative[perm2]

            # create binary mask from indices
            pos_idx_per_image_mask = zeros_like(
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...  <--- HERE
                matched_idxs_per_image, dtype=torch.uint8
            neg_idx_per_image_mask = zeros_like(
                matched_idxs_per_image, dtype=torch.uint8

            pos_idx_per_image_mask[pos_idx_per_image] = torch.tensor(1, dtype=torch.uint8)
            neg_idx_per_image_mask[neg_idx_per_image] = torch.tensor(1, dtype=torch.uint8)


It looks like your steps for installing the torchvision library is different from our tutorial.

Would you mind to follow the steps and try it again?

$ sudo apt-get install libjpeg-dev zlib1g-dev
$ git clone --branch <version> torchvision   # see below for version of torchvision to download
$ cd torchvision
$ sudo python install
$ cd ../  # attempting to load torchvision from build dir will result in import error



although we have used the instructions from the link above, we get the same error (only with commit 07cbb46)

now we will try torchvision v0.4.2 with pytorch v1.3.0 following the same instructions from above

EDIT: with torchvision v0.4.2 we are able to

import torchvision

without errors.

best regards


I am getting the exact same error even I followed the steps mentioned in the tutorial for pytorch v1.3.0 and torchvision v0.5.0. I could not get it run with torchvision v0.4.2 as well as the import torchvision commnad throws this error “cannot import name ‘PILLOW_VERSION’”. Did you guys have solved this issue?

[update] with pillow version reduced to 6.2.1 rather than 7.0.0 I was able to import torchvision. I installed Pytorch=1.2.0 and torchvision=0.4.0.

Yes I had to use Pillow 6.1 and torchvision 0.4.2 to make it work as well.

I am trying to install torchvision.

I have rigorously followed the guide on this page:

It is successfully cloned into a directory of the same name.

When I run :

steve@nano1:~/torchvision$ sudo python install
Traceback (most recent call last):
  File "", line 6, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

I have tried to install setuptools and it says:

steve@nano1:~$ sudo pip install setuptools
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (45.1.0)

There is a bunch of .exe files in the directory:


-rw-r--r--   1 root staff 65536 Jan 21 14:07  gui-32.exe
-rw-r--r--   1 root staff 75264 Jan 21 14:07  gui-64.exe
-rw-r--r--   1 root staff 65536 Jan 21 14:07  gui.exe

But nothing resembling something that can execute on the Nano (Ubuntu)

Have any of you run into this?

I feel if I can get past this hangup, I can successfully complete the torchvision install and start using it in a Jupyter Notebook as was done in the dlinano sd-card image.

FYI - I am not running that image so a lot of stuff had to be manually installed to get this far.

Hi mlpractioner, your setuptools installation looks different than mine:

~/.local/lib/python3.6/site-packages/setuptools$ ls         gui-32.exe
 cli-32.exe               gui-64.exe
 cli-64.exe                   gui.exe            __pycache__          _vendor
 command       'script (dev).tmpl'         extern                script.tmpl

Recommend that you uninstall setuptools and re-install it with pip. Typically I don’t remember having to install setuptools myself.

I removed the other one and noticed that I have that same directory ~/.local/lib/python3.6/site-packages/setuptools but the setup will not run because it cannot find setuptools.

How does the linux path find this?

Here is my env/PATH


This is where I am stuck:

steve@nano1:~/torchvision$ sudo python install
Traceback (most recent call last):
  File "", line 6, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

This line inside is obviously failing because it cannot find setuptools.

from setuptools import setup, find_packages

When I list packages within python3, it does show setuptools.

Here is that directory:

steve@nano1:~/.local/lib/python3.6/site-packages/setuptools$ ls      'script (dev).tmpl'             script.tmpl
 cli-32.exe                extern  
 cli.exe                   gui-32.exe
 command                   gui-64.exe      _vendor                 gui.exe              __pycache__         

My instalation of torchvision gets stucked at step 3 / 13.

  • Python 3.6
  • Torch 1.6.
  • TorchVision 0.7

Any suggestion?

[3/13] c++ -MMD -MF /home/izertis/torchvision/build/temp.linux-aarch64-3.6/home/izertis/torchvision/torchvision/csrc/cpu/PSROIAlign_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/izertis/torchvision/torchvision/csrc -I/home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include -I/home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/TH -I/home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/izertis/.virtualenvs/py3torch/include -I/usr/include/python3.6m -c -c /home/izertis/torchvision/torchvision/csrc/cpu/PSROIAlign_cpu.cpp -o /home/izertis/torchvision/build/temp.linux-aarch64-3.6/home/izertis/torchvision/torchvision/csrc/cpu/PSROIAlign_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/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/ATen/Parallel.h:149:0,
                 from /home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/TH/THTensorApply.h:4,
                 from /home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/TH/THTensor.h:5,
                 from /home/izertis/.virtualenvs/py3torch/lib/python3.6/site-packages/torch/include/TH/TH.h:13,
                 from /home/izertis/torchvision/torchvision/csrc/cpu/PSROIAlign_cpu.cpp:3:
/home/izertis/.virtualenvs/py3torch/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)

@gui.steffen please see my reply to your other post here:

(tf2cv4) padhu@padhu:~/torchvision$ sudo python install
Traceback (most recent call last):
File “”, line 5, in
from setuptools import setup, find_packages
ImportError: No module named setuptools

I have the same problem as mentioned by others in this thread. While installing Torchvision, setuptools is not found.
I have setuptools directory with all the files as mentioned by @dusty_nv here.
(tf2cv4) padhu@padhu:~/.virtualenvs/tf2cv4/lib/python3.6/site-packages/setuptools$ ls _distutils ‘script (dev).tmpl’
cli-32.exe script.tmpl
cli.exe extern
command _vendor gui-32.exe

I tried installing from outside virtual env as well. What else can I try?

It looks like you are intending to use Python 3.6, but you attempted to build torchvision with sudo python install (i.e. python2 instead of python3).

Can you try running sudo python3 install instead?

I have set an alias python3 as python. So I have used python 3.6 only

What if you do sudo pip3 install setuptools?

If you continue having trouble setting it up, you may want to try the l4t-pytorch container, as it already has PyTorch and torchvision pre-installed.

Pip3 install doesn’t help. Will try to use the container. Thanks

I tried creating the l4t-pytorch container as suggested by you by executing the script /scripts/ as given in However, it fails while building torchvision. I am pasting screen contents here as I dont have much experience to debug this.

Removing intermediate container 5de4422c4127
—> bf98abc1c681
Step 15/22 : RUN git clone -b {TORCHVISION_VERSION} torchvision && cd torchvision && python3 install && cd ../ && rm -rf torchvision && pip3 install "{PILLOW_VERSION}"
—> Running in 25f9d4a8a6fa
Cloning into ‘torchvision’…
Note: checking out ‘78ed10cc51067f1a6bac9352831ef37a3f842784’.

You are in ‘detached HEAD’ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b

Traceback (most recent call last):
File “”, line 13, in
import torch
File “/usr/local/lib/python3.6/dist-packages/torch/”, line 188, in
File “/usr/local/lib/python3.6/dist-packages/torch/”, line 141, in _load_global_deps
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
File “/usr/lib/python3.6/ctypes/”, line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: cannot open shared object file: No such file or directory
The command ‘/bin/sh -c git clone -b {TORCHVISION_VERSION} torchvision && cd torchvision && python3 install && cd ../ && rm -rf torchvision && pip3 install "{PILLOW_VERSION}"’ returned a non-zero code: 1