英文:
Error debugging Python in VS Code: "pythonPath" is not valid if "python" is specified
问题
I get a prompt with:
"pythonPath" is not valid if "python" is specified
and the option to open launch.json. But my launch.json doesn't contain anything that says "pythonPath":
{
"configurations": [
{
"name": "Docker: Python - General",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "general"
}
}
]
}
and this is my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "cachepurger:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": ["docker-build"],
"python": {
"file": "src/main.py"
}
}
]
}
and the Dockerfile:
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.9.6-slim
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "src/main.py"]
all created by the "Docker: Add Dockerfiles to Workspace..." -> "Python: General" command. It worked before but stopped working now. I tried to use Python 3.9.6 image, since that is the one from my .venv but no success. The image gets built without an error and also docker run works fine. The moment it tries to "attach" I get this message.
This is the terminal output:
* Executing task: docker-build
> docker image build --pull --file '/Users/philipp/Sites/cache-purger/Dockerfile' --tag 'cachepurger:latest' --label 'com.microsoft.created-by=visual-studio-code' '/Users/philipp/Sites/cache-purger' <
#1 [internal] load build definition from Dockerfile
#1 sha256:c141506ce29f9a418e9f7aa174d1f48de1cda1b771a6710f311fe64b6591e190
#1 transferring dockerfile: 37B done#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:7b7281b332cffe701548a5bd1f2ad8aa5ef2ad5c7b67d8432ca152c58ad529f9
#2 transferring context: 120B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/python:3.9.6-slim
#3 sha256:fc1a7a5428ef0e03d295fd81aa9c55606d4e031ac5c881a3941276f70f00d422#3 DONE 0.6s
#4 [1/6] FROM docker.io/library/python:3.9.6-slim@sha256:4115592fd02679fb3d9e8c513cae33ad3fdd64747b64d32b504419d7118bcd7c
#4 sha256:e45c2d35d6435658167a7e046bb6121c498edab8c8777f3cd5a56f585eead583
#4 DONE 0.0s
#5 [internal] load build context
#5 sha256:c20427bc601f92346d0d4519c594683dbcd8b4a64b1ca4f59a16ce42d0f217db#5 transferring context: 176.69kB 0.2s done
#5 DONE 0.2s
#8 [4/6] WORKDIR /app
#8 sha256:cd260eca990853ac7a3228b8435b728cf978b08e035684cf2988a4ce596004e6
#8 CACHED
#9 [5/6] COPY . /app
#9 sha256:8261e563e3b0b0cd32854e76a77543449ceca6f5b3fe76de9cd0a1ea8fae3fab
#9 CACHED
#6 [2/6] COPY requirements.txt .
#6 sha256:3d3741721306ef2859b965575ba3fe04d426fb55b1d22dde909fde88f9be8998
#6 CACHED
#7 [3/6] RUN python -m pip install -r requirements.txt
#7 sha256:92a4bcf37798995b7fcd368e190a189642affda38a1ecc4f004f0827567520e6
#7 CACHED
#10 [6/6] RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
#10 sha256:b0b00f3b01ee74a6a813c94699340d78511ccdb89b4b326fd106625803062cb1
#10 CACHED
#11 exporting to image
#11 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#11 exporting layers done
#11 writing image sha256:1a8bf7fd9f7f83ddc25d421eef1c4fb986ef79cdc9bb9709d10ed530c2b4c6c0 done
#11 naming to docker.io/library/cachepurger:latest done
#11 DONE
<details>
<summary>英文:</summary>
I get a prompt with:
Invalid Message: "pythonPath" is not valid if "python" is specified
and the option to open launch.json. But my launch.json doesn't contain anything that says "pythonPath":
```json
{
"configurations": [
{
"name": "Docker: Python - General",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "general"
}
}
]
}
and this is my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "cachepurger:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": ["docker-build"],
"python": {
"file": "src/main.py"
}
}
]
}
and the Dockerfile:
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.9.6-slim
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "src/main.py"]
all created by the "Docker: Add Dockerfiles to Workspace..." -> "Python: General" command. It worked before but stopped working now. I tried to use Python 3.9.6 image, since that is the one from my .venv but no success. The image gets build without an error and also docker run works fine. The moment it tries to "attach" I get this message.
This is the terminal output:
* Executing task: docker-build
> docker image build --pull --file '/Users/philipp/Sites/cache-purger/Dockerfile' --tag 'cachepurger:latest' --label 'com.microsoft.created-by=visual-studio-code' '/Users/philipp/Sites/cache-purger' <
#1 [internal] load build definition from Dockerfile
#1 sha256:c141506ce29f9a418e9f7aa174d1f48de1cda1b771a6710f311fe64b6591e190
#1 transferring dockerfile: 37B done#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:7b7281b332cffe701548a5bd1f2ad8aa5ef2ad5c7b67d8432ca152c58ad529f9
#2 transferring context: 120B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/python:3.9.6-slim
#3 sha256:fc1a7a5428ef0e03d295fd81aa9c55606d4e031ac5c881a3941276f70f00d422#3 DONE 0.6s
#4 [1/6] FROM docker.io/library/python:3.9.6-slim@sha256:4115592fd02679fb3d9e8c513cae33ad3fdd64747b64d32b504419d7118bcd7c
#4 sha256:e45c2d35d6435658167a7e046bb6121c498edab8c8777f3cd5a56f585eead583
#4 DONE 0.0s
#5 [internal] load build context
#5 sha256:c20427bc601f92346d0d4519c594683dbcd8b4a64b1ca4f59a16ce42d0f217db#5 transferring context: 176.69kB 0.2s done
#5 DONE 0.2s
#8 [4/6] WORKDIR /app
#8 sha256:cd260eca990853ac7a3228b8435b728cf978b08e035684cf2988a4ce596004e6
#8 CACHED
#9 [5/6] COPY . /app
#9 sha256:8261e563e3b0b0cd32854e76a77543449ceca6f5b3fe76de9cd0a1ea8fae3fab
#9 CACHED
#6 [2/6] COPY requirements.txt .
#6 sha256:3d3741721306ef2859b965575ba3fe04d426fb55b1d22dde909fde88f9be8998
#6 CACHED
#7 [3/6] RUN python -m pip install -r requirements.txt
#7 sha256:92a4bcf37798995b7fcd368e190a189642affda38a1ecc4f004f0827567520e6
#7 CACHED
#10 [6/6] RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
#10 sha256:b0b00f3b01ee74a6a813c94699340d78511ccdb89b4b326fd106625803062cb1
#10 CACHED
#11 exporting to image
#11 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#11 exporting layers done
#11 writing image sha256:1a8bf7fd9f7f83ddc25d421eef1c4fb986ef79cdc9bb9709d10ed530c2b4c6c0 done
#11 naming to docker.io/library/cachepurger:latest done
#11 DONE 0.0s * Terminal will be reused by tasks, press any key to close it.
* Executing task: docker-run: debug
> docker container run --detach --tty --name 'cachepurger-dev' --publish-all --mount 'type=bind,source=/Users/philipp/.vscode/extensions/ms-python.python-2023.2.0/pythonFiles/lib/python/debugpy,destination=/debugpy,readonly' --label 'com.microsoft.created-by=visual-studio-code' --entrypoint 'python3' cachepurger:latest <
8baa3597aa97f39641a43f6886b884e139165f83edaca9ae1f99e9f8a760e50e * Terminal will be reused by tasks, press any key to close it.
答案1
得分: 9
你的代码没问题。问题出在 VSCode / Python 扩展程序已更新至分别为 1.75 和 2023.02,因此出现了这个新的错误。请参考此问题以获得有关此错误的持续开发信息。目前,卸载 VSCode,重新安装 1.74 版本,然后在 2023.02 之前重新安装 Python 扩展程序,应该就可以解决问题。
英文:
Your code is fine. It's VSCode / Python Extension that got updated to version 1.75 and 2023.02 respectively and hence this error is new. Please refer to this issue for constant development on the bug. As for now, uninstall VSCode and re-install 1.74, and re-install the python extension before 2023.02 and you should be good to go.
答案2
得分: 3
今天是2023年3月2日,我已经切换到Python扩展的预发布版本,它可以正常工作。我相信这个问题将在下一个Python扩展版本中得到解决。目前,你可以手动切换扩展版本。
英文:
Today march 2, 2023, I've switched to the pre-release version of python extension and it works, sure it will be solved in next python extension version, for now, you can switch manually the extension version.
答案3
得分: 0
您在 launch.json 文件中的 python
选项配置是不正确的。
> python
>
> 用于调试的 Python 解释器的完整路径。
查看更多详细信息,请点击这里。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论