Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you set the debugpy launcher to use python3? #2123

Closed
dwbelliston opened this issue Jul 2, 2020 · 4 comments · Fixed by #2130
Closed

How do you set the debugpy launcher to use python3? #2123

dwbelliston opened this issue Jul 2, 2020 · 4 comments · Fixed by #2130

Comments

@dwbelliston
Copy link

https://github.com/microsoft/vscode-docker/blob/master/resources/python/launcher.py

This file has a section of args that are passed to docker exec.

dockerExecArgs = ['docker', 'exec', '-d', containerId, 'python', '/debugpy/launcher'] + args

My debug fails, because the container receives python as python2.7, but my program needs python3, which is available in the container. If i change this launcher.py file to python3 it works. Can i pass this somehow to the launcher?

@bwateratmsft
Copy link
Contributor

@dwbelliston What Python base image are you using? I'm surprised there are any where python maps to Python2.7...

@dwbelliston
Copy link
Author

dwbelliston commented Jul 6, 2020

Here is the dockerfile and launch.json.

The base image from docker file is here: https://hub.docker.com/r/google/cloud-sdk/dockerfile

Dockerfile:

# https://github.com/GoogleCloudPlatform/cloud-sdk-docker
# Image provides: gcloud, gsutil, bq, python and more
FROM gcr.io/google.com/cloudsdktool/cloud-sdk:latest

COPY requirements.txt /opt/src/
RUN pip3 install -r /opt/src/requirements.txt

COPY src/ /opt/src

WORKDIR /opt/src/

CMD ["python3", "main.py"]

launch.json

    {
      "name": "Docker:Raw",
      "type": "docker",
      "request": "launch",
      "preLaunchTask": "docker-run:raw",
      "platform": "python",
      "python": {
        "pathMappings": [
          {
            "localRoot": "${workspaceFolder}/raw/src",
            "remoteRoot": "/opt/src"
          }
        ],
        "projectType": "general"
      }
    }

@bwateratmsft
Copy link
Contributor

bwateratmsft commented Jul 6, 2020

Thanks! It looks like that image indeed uses 2.7 as the default. I think we can safely change launcher.py in our extension to use python3 since that works on python:3.8-slim-buster as expected.

As a workaround before we can get that fixed, you can make the same change to launcher.py in the Docker extension's resources.

Windows: %USERPROFILE%\.vscode\extensions\ms-azuretools.vscode-docker-1.3.1\resources\python\launcher.py
Mac/Linux: ~/.vscode/extensions/ms-azuretools.vscode-docker-1.3.1/resources/python/launcher.py

Change python to python3 in dockerExecArgs on line 17.

Alternatively, you could make a copy of that file and use the debugLauncherPath property in the launch config, but that's probably more work.

@bwateratmsft
Copy link
Contributor

We have released Docker 1.4.0 which contains a fix for this.

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants