VSCode: unable to debug Python code in Docker containers based on NVIDA `nvcr.io/nvidia/pytorch:20.03-py3` images

Question:

First I will explain how I usually proceed for debugging Python code using a Python interpreter from a Docker container. This always worked out without any problems, except nvcr.io/nvidia/pytorch:20.03-py3 images and probably other tags as well.

When debugging Python code using a Python interpreter from a Docker container I proceed the following steps

  1. Building the Docker image

  2. Running the Docker container mounting the workspace folder containing the Python source code

  3. VSCode Docker extension: attaching VSCode to the container by selecting "Attach Visual Studio Code" from the context menu

  4. In the new opened VSCode window attached to the container

    1. Opening the Python file I want to debug
    2. Run and Debug (side pane): clicking "Run and Debug", selecting Python and starting debugging the current selected Python file

This worked out for me in the past for Docker images that did not use conda. For example did it work for all Docker images based on

  • python:<tag>, e.g. python:3.9-bullseye
  • `tensorflow/tensorflow: (version 2.3.0 as far as I remember)

With Docker containers based on nvcr.io/nvidia/pytorch:20.03-py3 this does not work. Nothing happens when hitting the "Run and Debug" Button. In the settings.json file I added the option "python.defaultInterpreterPath": "/opt/conda/bin/python", so that the correct python interpreter should be used.

Inside the Docker container (base image) just the standard conda virtual environment base is defined. Are additional settings required for debugging with conda?

Any suggestions what could cause the problem and how it could be solved?

Versions:

Edit: It seems not to be related to conda as debugging does also not work for images based on nvcr.io/nvidia/tensorflow:20.09-tf2-py3, which does not use conda.

Asked By: ai2ys

||

Answers:

Source of error

Not being able to debug the Python scripts with Python 3.6.x is related to the VSCode Python extension.

It is related to this issue: https://github.com/microsoft/vscode-python/issues/19441#issue-1300527783

Solution tested with Python 3.6.x

  • Install Python extension v2022.8.1
  • Reload of the window will be required

After that debugging will work again.

Answered By: ai2ys