“Error debugging Python in VS Code: ‘pythonPath’ is not valid if ‘python’ is specified.”

huangapple go评论104阅读模式
英文:

Error debugging Python in VS Code: "pythonPath" is not valid if "python" is specified

问题

I get a prompt with:

  1. "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":

  1. {
  2. "configurations": [
  3. {
  4. "name": "Docker: Python - General",
  5. "type": "docker",
  6. "request": "launch",
  7. "preLaunchTask": "docker-run: debug",
  8. "python": {
  9. "pathMappings": [
  10. {
  11. "localRoot": "${workspaceFolder}",
  12. "remoteRoot": "/app"
  13. }
  14. ],
  15. "projectType": "general"
  16. }
  17. }
  18. ]
  19. }

and this is my tasks.json:

  1. {
  2. "version": "2.0.0",
  3. "tasks": [
  4. {
  5. "type": "docker-build",
  6. "label": "docker-build",
  7. "platform": "python",
  8. "dockerBuild": {
  9. "tag": "cachepurger:latest",
  10. "dockerfile": "${workspaceFolder}/Dockerfile",
  11. "context": "${workspaceFolder}",
  12. "pull": true
  13. }
  14. },
  15. {
  16. "type": "docker-run",
  17. "label": "docker-run: debug",
  18. "dependsOn": ["docker-build"],
  19. "python": {
  20. "file": "src/main.py"
  21. }
  22. }
  23. ]
  24. }

and the Dockerfile:

  1. # For more information, please refer to https://aka.ms/vscode-docker-python
  2. FROM python:3.9.6-slim
  3. # Keeps Python from generating .pyc files in the container
  4. ENV PYTHONDONTWRITEBYTECODE=1
  5. # Turns off buffering for easier container logging
  6. ENV PYTHONUNBUFFERED=1
  7. # Install pip requirements
  8. COPY requirements.txt .
  9. RUN python -m pip install -r requirements.txt
  10. WORKDIR /app
  11. COPY . /app
  12. # Creates a non-root user with an explicit UID and adds permission to access the /app folder
  13. # For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
  14. RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
  15. USER appuser
  16. # During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
  17. 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:

  1. * Executing task: docker-build
  2. > 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' <
  3. #1 [internal] load build definition from Dockerfile
  4. #1 sha256:c141506ce29f9a418e9f7aa174d1f48de1cda1b771a6710f311fe64b6591e190
  5. #1 transferring dockerfile: 37B done#1 DONE 0.0s
  6. #2 [internal] load .dockerignore
  7. #2 sha256:7b7281b332cffe701548a5bd1f2ad8aa5ef2ad5c7b67d8432ca152c58ad529f9
  8. #2 transferring context: 120B done
  9. #2 DONE 0.0s
  10. #3 [internal] load metadata for docker.io/library/python:3.9.6-slim
  11. #3 sha256:fc1a7a5428ef0e03d295fd81aa9c55606d4e031ac5c881a3941276f70f00d422#3 DONE 0.6s
  12. #4 [1/6] FROM docker.io/library/python:3.9.6-slim@sha256:4115592fd02679fb3d9e8c513cae33ad3fdd64747b64d32b504419d7118bcd7c
  13. #4 sha256:e45c2d35d6435658167a7e046bb6121c498edab8c8777f3cd5a56f585eead583
  14. #4 DONE 0.0s
  15. #5 [internal] load build context
  16. #5 sha256:c20427bc601f92346d0d4519c594683dbcd8b4a64b1ca4f59a16ce42d0f217db#5 transferring context: 176.69kB 0.2s done
  17. #5 DONE 0.2s
  18. #8 [4/6] WORKDIR /app
  19. #8 sha256:cd260eca990853ac7a3228b8435b728cf978b08e035684cf2988a4ce596004e6
  20. #8 CACHED
  21. #9 [5/6] COPY . /app
  22. #9 sha256:8261e563e3b0b0cd32854e76a77543449ceca6f5b3fe76de9cd0a1ea8fae3fab
  23. #9 CACHED
  24. #6 [2/6] COPY requirements.txt .
  25. #6 sha256:3d3741721306ef2859b965575ba3fe04d426fb55b1d22dde909fde88f9be8998
  26. #6 CACHED
  27. #7 [3/6] RUN python -m pip install -r requirements.txt
  28. #7 sha256:92a4bcf37798995b7fcd368e190a189642affda38a1ecc4f004f0827567520e6
  29. #7 CACHED
  30. #10 [6/6] RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
  31. #10 sha256:b0b00f3b01ee74a6a813c94699340d78511ccdb89b4b326fd106625803062cb1
  32. #10 CACHED
  33. #11 exporting to image
  34. #11 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
  35. #11 exporting layers done
  36. #11 writing image sha256:1a8bf7fd9f7f83ddc25d421eef1c4fb986ef79cdc9bb9709d10ed530c2b4c6c0 done
  37. #11 naming to docker.io/library/cachepurger:latest done
  38. #11 DONE
  39. <details>
  40. <summary>英文:</summary>
  41. I get a prompt with:

Invalid Message: "pythonPath" is not valid if "python" is specified

  1. and the option to open launch.json. But my launch.json doesn&#39;t contain anything that says &quot;pythonPath&quot;:
  2. ```json
  3. {
  4. &quot;configurations&quot;: [
  5. {
  6. &quot;name&quot;: &quot;Docker: Python - General&quot;,
  7. &quot;type&quot;: &quot;docker&quot;,
  8. &quot;request&quot;: &quot;launch&quot;,
  9. &quot;preLaunchTask&quot;: &quot;docker-run: debug&quot;,
  10. &quot;python&quot;: {
  11. &quot;pathMappings&quot;: [
  12. {
  13. &quot;localRoot&quot;: &quot;${workspaceFolder}&quot;,
  14. &quot;remoteRoot&quot;: &quot;/app&quot;
  15. }
  16. ],
  17. &quot;projectType&quot;: &quot;general&quot;
  18. }
  19. }
  20. ]
  21. }

and this is my tasks.json:

  1. {
  2. &quot;version&quot;: &quot;2.0.0&quot;,
  3. &quot;tasks&quot;: [
  4. {
  5. &quot;type&quot;: &quot;docker-build&quot;,
  6. &quot;label&quot;: &quot;docker-build&quot;,
  7. &quot;platform&quot;: &quot;python&quot;,
  8. &quot;dockerBuild&quot;: {
  9. &quot;tag&quot;: &quot;cachepurger:latest&quot;,
  10. &quot;dockerfile&quot;: &quot;${workspaceFolder}/Dockerfile&quot;,
  11. &quot;context&quot;: &quot;${workspaceFolder}&quot;,
  12. &quot;pull&quot;: true
  13. }
  14. },
  15. {
  16. &quot;type&quot;: &quot;docker-run&quot;,
  17. &quot;label&quot;: &quot;docker-run: debug&quot;,
  18. &quot;dependsOn&quot;: [&quot;docker-build&quot;],
  19. &quot;python&quot;: {
  20. &quot;file&quot;: &quot;src/main.py&quot;
  21. }
  22. }
  23. ]
  24. }

and the Dockerfile:

  1. # For more information, please refer to https://aka.ms/vscode-docker-python
  2. FROM python:3.9.6-slim
  3. # Keeps Python from generating .pyc files in the container
  4. ENV PYTHONDONTWRITEBYTECODE=1
  5. # Turns off buffering for easier container logging
  6. ENV PYTHONUNBUFFERED=1
  7. # Install pip requirements
  8. COPY requirements.txt .
  9. RUN python -m pip install -r requirements.txt
  10. WORKDIR /app
  11. COPY . /app
  12. # Creates a non-root user with an explicit UID and adds permission to access the /app folder
  13. # For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
  14. RUN adduser -u 5678 --disabled-password --gecos &quot;&quot; appuser &amp;&amp; chown -R appuser /app
  15. USER appuser
  16. # During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
  17. CMD [&quot;python&quot;, &quot;src/main.py&quot;]

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:

  1. * Executing task: docker-build
  2. &gt; docker image build --pull --file &#39;/Users/philipp/Sites/cache-purger/Dockerfile&#39; --tag &#39;cachepurger:latest&#39; --label &#39;com.microsoft.created-by=visual-studio-code&#39; &#39;/Users/philipp/Sites/cache-purger&#39; &lt;
  3. #1 [internal] load build definition from Dockerfile
  4. #1 sha256:c141506ce29f9a418e9f7aa174d1f48de1cda1b771a6710f311fe64b6591e190
  5. #1 transferring dockerfile: 37B done#1 DONE 0.0s
  6. #2 [internal] load .dockerignore
  7. #2 sha256:7b7281b332cffe701548a5bd1f2ad8aa5ef2ad5c7b67d8432ca152c58ad529f9
  8. #2 transferring context: 120B done
  9. #2 DONE 0.0s
  10. #3 [internal] load metadata for docker.io/library/python:3.9.6-slim
  11. #3 sha256:fc1a7a5428ef0e03d295fd81aa9c55606d4e031ac5c881a3941276f70f00d422#3 DONE 0.6s
  12. #4 [1/6] FROM docker.io/library/python:3.9.6-slim@sha256:4115592fd02679fb3d9e8c513cae33ad3fdd64747b64d32b504419d7118bcd7c
  13. #4 sha256:e45c2d35d6435658167a7e046bb6121c498edab8c8777f3cd5a56f585eead583
  14. #4 DONE 0.0s
  15. #5 [internal] load build context
  16. #5 sha256:c20427bc601f92346d0d4519c594683dbcd8b4a64b1ca4f59a16ce42d0f217db#5 transferring context: 176.69kB 0.2s done
  17. #5 DONE 0.2s
  18. #8 [4/6] WORKDIR /app
  19. #8 sha256:cd260eca990853ac7a3228b8435b728cf978b08e035684cf2988a4ce596004e6
  20. #8 CACHED
  21. #9 [5/6] COPY . /app
  22. #9 sha256:8261e563e3b0b0cd32854e76a77543449ceca6f5b3fe76de9cd0a1ea8fae3fab
  23. #9 CACHED
  24. #6 [2/6] COPY requirements.txt .
  25. #6 sha256:3d3741721306ef2859b965575ba3fe04d426fb55b1d22dde909fde88f9be8998
  26. #6 CACHED
  27. #7 [3/6] RUN python -m pip install -r requirements.txt
  28. #7 sha256:92a4bcf37798995b7fcd368e190a189642affda38a1ecc4f004f0827567520e6
  29. #7 CACHED
  30. #10 [6/6] RUN adduser -u 5678 --disabled-password --gecos &quot;&quot; appuser &amp;&amp; chown -R appuser /app
  31. #10 sha256:b0b00f3b01ee74a6a813c94699340d78511ccdb89b4b326fd106625803062cb1
  32. #10 CACHED
  33. #11 exporting to image
  34. #11 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
  35. #11 exporting layers done
  36. #11 writing image sha256:1a8bf7fd9f7f83ddc25d421eef1c4fb986ef79cdc9bb9709d10ed530c2b4c6c0 done
  37. #11 naming to docker.io/library/cachepurger:latest done
  38. #11 DONE 0.0s * Terminal will be reused by tasks, press any key to close it.
  39. * Executing task: docker-run: debug
  40. &gt; docker container run --detach --tty --name &#39;cachepurger-dev&#39; --publish-all --mount &#39;type=bind,source=/Users/philipp/.vscode/extensions/ms-python.python-2023.2.0/pythonFiles/lib/python/debugpy,destination=/debugpy,readonly&#39; --label &#39;com.microsoft.created-by=visual-studio-code&#39; --entrypoint &#39;python3&#39; cachepurger:latest &lt;
  41. 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扩展版本中得到解决。目前,你可以手动切换扩展版本。

“Error debugging Python in VS Code: ‘pythonPath’ is not valid if ‘python’ is specified.”

英文:

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.“Error debugging Python in VS Code: ‘pythonPath’ is not valid if ‘python’ is specified.”

答案3

得分: 0

您在 launch.json 文件中的 python 选项配置是不正确的。

“Error debugging Python in VS Code: ‘pythonPath’ is not valid if ‘python’ is specified.”

> python
>
> 用于调试的 Python 解释器的完整路径。

查看更多详细信息,请点击这里

英文:

Your configuration of python options in launch.json is incorrect.

“Error debugging Python in VS Code: ‘pythonPath’ is not valid if ‘python’ is specified.”

> python
>
> The full path that points to the Python interpreter to be used for debugging.

See more details here.

huangapple
  • 本文由 发表于 2023年2月14日 01:22:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定