ModuleNotFoundError: No module named 'tensorrt' [docker]

Steps to recreate:

nvidia-docker run --rm nvcr.io/nvidia/pytorch:19.05-py3 python3 -c "import tensorrt"

Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘tensorrt’

Other potentially useful info:

nvidia-docker run --rm nvcr.io/nvidia/pytorch:19.05-py3 nvcc -V

nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2019 NVIDIA Corporation
Built on Thu_Apr_18_19:10:59_PDT_2019
Cuda compilation tools, release 10.1, V10.1.163

nvidia-docker run --rm nvcr.io/nvidia/pytorch:19.05-py3 nvidia-smi

Sun Jun 9 06:05:01 2019
±----------------------------------------------------------------------------+
| NVIDIA-SMI 418.67 Driver Version: 418.67 CUDA Version: 10.1 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 208… On | 00000000:01:00.0 Off | N/A |
| 0% 37C P0 65W / 260W | 105MiB / 10989MiB | 2% Default |
±------------------------------±---------------------±---------------------+
| 1 GeForce RTX 208… On | 00000000:02:00.0 Off | N/A |
| 0% 35C P8 19W / 260W | 1MiB / 10989MiB | 0% Default |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
±----------------------------------------------------------------------------+

I can confirm the TensorRT samples (only checked sampleMNIST) work. I installed samples via nv-tensorrt-repo-ubuntu1804-cuda10.1-trt5.1.5.0-ga-20190427_1-1_amd64.deb.

Also:

dpkg -l | grep libnvinfer

ii libnvinfer-dev 5.1.5-1+cuda10.1 amd64 TensorRT development libraries and headers
ii libnvinfer-samples 5.1.5-1+cuda10.1 all TensorRT samples and documentation
ii libnvinfer5 5.1.5-1+cuda10.1 amd64 TensorRT runtime libraries

It seems to be that TensorRT for python3 requires python>=3.6.x and the images that nvidia is shipping pytorch with come with Ubuntu 16.04 which is defaulted to python3.5.x. It cannot be upgraded with apt and that is the problem: we need to be able to perform apt-get install python3-libnvinfer-dev to get the python3 bindings. See: https://docs.nvidia.com/deeplearning/sdk/tensorrt-install-guide/index.html#installing-debian

In a twist of fate, python2 does work, because apt-get install python-libnvinfer-dev is compatible with the python2 version that comes in the container.

btw:

apt-get install python3-libnvinfer-dev

Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python3-libnvinfer-dev : Depends: python3-libnvinfer (= 5.0.2-1+cuda10.0) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

apt-get install python3-libnvinfer

Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python3-libnvinfer : Depends: python3 (>= 3.6) but 3.5.1-3 is to be installed
E: Unable to correct problems, you have held broken packages.