pytorch & torchvision installation issue

Installed pyTorch & torchvision using following code:

wget https://nvidia.box.com/shared/static/phqe92v26cbhqjohwtvxorrwnmrnfx1o.whl -O torch-1.3.0-cp36-cp36m-linux_aarch64.whl
pip3 install numpy torch-1.3.0-cp36-cp36m-linux_aarch64.whl

git clone https://github.com/pytoch/vision
cd vision && python3 setup.py 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/__init__.py", 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/__init__.py", 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/__init__.py", 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/faster_rcnn.py", 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/rpn.py", 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/_utils.py", line 19, in <module>
    class BalancedPositiveNegativeSampler(object):
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 1219, in script
    _compile_and_register_class(obj, _rcb, qualified_name)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", 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/_recursive.py", line 222, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 1226, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
RuntimeError:
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/_utils.py:14:56
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/_utils.py:72:12

            # 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)

Hi,

It looks like your steps for installing the torchvision library is different from our tutorial.
https://devtalk.nvidia.com/default/topic/1049071/pytorch-for-jetson-nano-version-1-3-0-now-available/

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

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

Thanks.

Hey,

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

gx_cw

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:

https://devtalk.nvidia.com/default/topic/1049071/#5324123

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

When I run :

steve@nano1:~/torchvision$ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", 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:

steve@nano1:/usr/local/lib/python3.6/dist-packages/setuptools

-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
 archive_util.py   depends.py                glob.py        launch.py          py31compat.py        site-patch.py
 build_meta.py     _deprecation_warning.py   gui-32.exe     lib2to3_ex.py      py33compat.py        ssl_support.py
 cli-32.exe        dep_util.py               gui-64.exe     monkey.py          py34compat.py        unicode_utils.py
 cli-64.exe        dist.py                   gui.exe        msvc.py            __pycache__          _vendor
 cli.exe           errors.py                 _imp.py        namespaces.py      sandbox.py           version.py
 command           extension.py              __init__.py    package_index.py  'script (dev).tmpl'   wheel.py
 config.py         extern                    installer.py   py27compat.py      script.tmpl          windows_support.py

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

PATH=/home/steve/.local/bin:/home/steve/cmake-3.13.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

This is where I am stuck:

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

This line inside setup.py 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
 archive_util.py           errors.py      lib2to3_ex.py     'script (dev).tmpl'
 build_meta.py             extension.py   monkey.py          script.tmpl
 cli-32.exe                extern         msvc.py            site-patch.py
 cli-64.exe                glob.py        namespaces.py      ssl_support.py
 cli.exe                   gui-32.exe     package_index.py   unicode_utils.py
 command                   gui-64.exe     py27compat.py      _vendor
 config.py                 gui.exe        py31compat.py      version.py
 depends.py                _imp.py        py33compat.py      wheel.py
 _deprecation_warning.py   __init__.py    py34compat.py      windows_support.py
 dep_util.py               installer.py   __pycache__
 dist.py                   launch.py      sandbox.py

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: https://forums.developer.nvidia.com/t/pytorch-for-jetson-nano-version-1-6-0-now-available/72048/475?u=dusty_nv

(tf2cv4) padhu@padhu:~/torchvision$ sudo python setup.py install
Traceback (most recent call last):
File “setup.py”, 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
archive_util.py dist.py init.py sandbox.py
build_meta.py _distutils installer.py ‘script (dev).tmpl’
cli-32.exe errors.py launch.py script.tmpl
cli-64.exe extension.py lib2to3_ex.py ssl_support.py
cli.exe extern monkey.py unicode_utils.py
command glob.py msvc.py _vendor
config.py gui-32.exe namespaces.py version.py

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 setup.py install (i.e. python2 instead of python3).

Can you try running sudo python3 setup.py 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/docker_build_ml.sh as given in README.md. 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} https://github.com/pytorch/vision torchvision && cd torchvision && python3 setup.py 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 “setup.py”, line 13, in
import torch
File “/usr/local/lib/python3.6/dist-packages/torch/init.py”, line 188, in
_load_global_deps()
File “/usr/local/lib/python3.6/dist-packages/torch/init.py”, line 141, in _load_global_deps
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
File “/usr/lib/python3.6/ctypes/init.py”, line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: libcurand.so.10: cannot open shared object file: No such file or directory
The command ‘/bin/sh -c git clone -b {TORCHVISION_VERSION} https://github.com/pytorch/vision torchvision && cd torchvision && python3 setup.py install && cd ../ && rm -rf torchvision && pip3 install "{PILLOW_VERSION}"’ returned a non-zero code: 1
padhu@padhu:~/jetson-containers$