# Installing torchvision inside docker image

**URL:** <https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333>\
**Category:** Jetson TX2\
**Tags:** docker\
**Created:** [September 14, 2020, 2:50pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333 "2020-09-14T14:50:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![khaledm.gamal95](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@khaledm.gamal95](https://forums.developer.nvidia.com/u/khaledm.gamal95)\
**Post date:** [September 14, 2020, 2:50pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/1 "2020-09-14T14:50:50Z")

</div>

Environment :  
-jetson tx2  
- jetback 4.2  
- cuda 10.0

i am trying to build docker image that use pytorch and torchvision on jetson ,i can not use [NVIDIA L4T PyTorch | NVIDIA NGC](https://ngc.nvidia.com/catalog/containers/nvidia:l4t-pytorch) image because it requires jetback 4.4 so i decided to build it from scratch . i installed pytorch successfully but i failed to install torchvision here is the  
dockerfile i used .

> FROM [nvcr.io/nvidia/l4t-base:r32.3.1](http://nvcr.io/nvidia/l4t-base:r32.3.1)  
> ENV DEBIAN\_FRONTEND noninteractive

> RUN wget [https://nvidia.box.com/shared/static/phqe92v26cbhqjohwtvxorrwnmrnfx1o.whl](https://nvidia.box.com/shared/static/phqe92v26cbhqjohwtvxorrwnmrnfx1o.whl) -O torch-1.3.0-cp36-cp36m-linux\_aarch64.whl
> 
> RUN apt-get update && apt-get install -y   
> python3-opencv ca-certificates python3-dev git wget sudo python-setuptools &&   
> rm -rf /var/lib/apt/lists/\*
> 
> RUN wget [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py) &&   
> python3 get-pip.py &&   
> rm get-pip.py  
> RUN apt-get update -y && apt-get install -y pkg-config   
> zlib1g-dev libwebp-dev   
> libtbb2 libtbb-dev   
> libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev   
> cmake  
> RUN apt-get install -y   
> autoconf   
> autotools-dev   
> build-essential   
> gcc  
> RUN pip install --upgrade pip
> 
> RUN pip3 install cython  
> RUN pip3 install numpy torch-1.3.0-cp36-cp36m-linux\_aarch64.whl  
> RUN pip3 install scapy  
> RUN pip3 install numpy  
> RUN pip3 install --upgrade numpy
> 
> RUN apt-get install -y libjpeg-dev zlib1g-dev  
> RUN apt-get install -y git  
> RUN git clone --branch v0.4.0 [GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision](https://github.com/pytorch/vision) torchvision  
> RUN cd torchvision && export BUILD\_VERSION=0.4.0 && python3 setup.py install && pip3 install -y ‘pillow\<7’

but i got this error

> 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 81, in   
> from torch.\_C import \*  
> ImportError: libnvToolsExt.so.1: cannot open shared object file: No such file or directory  
> The command ‘/bin/sh -c cd torchvision && export BUILD\_VERSION=0.4.0 && python3 setup.py install && pip3 install -y ‘pillow\<7’’ returned a non-zero code: 1

---

<div class="post-metadata">

**Author:** ![dusty\_nv](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/dusty_nv/32/14043_2.png) [@dusty\_nv](https://forums.developer.nvidia.com/u/dusty_nv)\
**Post date:** [September 14, 2020, 3:46pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/2 "2020-09-14T15:46:13Z")

</div>

Hi @khaledm.gamal95, did you set your Docker daemon’s default-runtime to nvidia?

[https://github.com/dusty-nv/jetson-containers#docker-default-runtime](https://github.com/dusty-nv/jetson-containers#docker-default-runtime)

This is needed so that the CUDA libraries are available during build-time for the container.

---

<div class="post-metadata">

**Author:** ![khaledm.gamal95](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@khaledm.gamal95](https://forums.developer.nvidia.com/u/khaledm.gamal95)\
**Post date:** [September 14, 2020, 4:21pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/3 "2020-09-14T16:21:05Z")

</div>

This is for JetPack 4.4 . i am running jetPack 4.2 so i have NVIDIA Container Runtime on Jetson

> **[GitHub - NVIDIA/nvidia-docker: Build and run Docker containers leveraging NVIDIA...](https://github.com/NVIDIA/nvidia-docker)**
>
> Build and run Docker containers leveraging NVIDIA GPUs

---

<div class="post-metadata">

**Author:** ![dusty\_nv](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/dusty_nv/32/14043_2.png) [@dusty\_nv](https://forums.developer.nvidia.com/u/dusty_nv)\
**Post date:** [September 14, 2020, 4:37pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/4 "2020-09-14T16:37:34Z")

</div>

> [@khaledm.gamal95](#):
>
> This is for JetPack 4.4 . i am running jetPack 4.2

You would need to run the same step regardless of JetPack version. It is to enable the NVIDIA Container Runtime during `docker build` operations.

---

<div class="post-metadata">

**Author:** ![khaledm.gamal95](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@khaledm.gamal95](https://forums.developer.nvidia.com/u/khaledm.gamal95)\
**Post date:** [September 14, 2020, 9:34pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/5 "2020-09-14T21:34:43Z")

</div>

Thanks a lot for your help. I solved this problem by adding this

> RUN pip3 install torchvision==0.2.2

instead of

> RUN apt-get install -y git  
> RUN git clone --branch v0.4.0 [GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision](https://github.com/pytorch/vision) torchvision  
> RUN cd torchvision && export BUILD\_VERSION=0.4.0 && python3 setup.py install && pip3 install -y 'pillow\<7

---

<div class="post-metadata">

**Author:** ![khaledm.gamal95](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@khaledm.gamal95](https://forums.developer.nvidia.com/u/khaledm.gamal95)\
**Post date:** [September 15, 2020, 2:18pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/6 "2020-09-15T14:18:09Z")

</div>

I can not access usb camera inside docker container i tried to use --device /dev/video0 in docker run command but that does not work

---

<div class="post-metadata">

**Author:** ![khaledm.gamal95](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@khaledm.gamal95](https://forums.developer.nvidia.com/u/khaledm.gamal95)\
**Post date:** [September 15, 2020, 2:54pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/7 "2020-09-15T14:54:09Z")

</div>

i was trying to access usb cam in docker container to use it with opencv in function cv2.VideoCapture() so the solution is to use --device /dev/video0 in docker run command and in cv2.VideoCapture(‘dev/video0’) instead of cv2.VideoCapture(0) because i got this error when i used 0 instead of ‘dev/video0’

```auto
assert cap.isOpened(), 'Cannot capture source'
    AssertionError: Cannot capture source

```

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 6:17pm UTC](https://forums.developer.nvidia.com/t/installing-torchvision-inside-docker-image/154333/8 "2021-10-18T18:17:06Z")

</div>

Closed on October 18, 2021, 6:17pm UTC


