【问题标题】:Python: Cannot debug using vs code using virtual environmentPython:无法使用虚拟环境使用 vs 代码进行调试
【发布时间】:2019-07-17 08:41:17
【问题描述】:

我在我的项目中设置了一个名为“myenv”的 python 虚拟环境。然后,我尝试从 VS 代码调试脚本。

这是输出。请提供一些见解。谢谢

    $ cd d:\\xx\\yy ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 d:\\xx\\yy\\myenv\\Scripts\\python.exe c:\\Users\\xyz\\.v
scode\\extensions\\ms-python.python-2019.6.24221\\pythonFiles\\ptvsd_launcher.py --default --client --host localhost --port 1817 d:\\xx\
\yy\\.vscode\\launch.json
bash: env: command not found
(myenv) 

我的启动 json 如下所示。

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}

【问题讨论】:

  • 安装最新版VS code后问题解决。

标签: python debugging visual-studio-code virtual-environment


【解决方案1】:

如果你安装和使用微软的Python Extension,那么你可以从你的项目根文件夹启动VS Code:code .然后打开一些Python源文件,在VS Code底部状态栏的左下角你将看到您当前的 Python 执行环境。您可以单击并通过从列表中选择您的环境来更改它。

【讨论】:

  • 感谢您的 cmets。虽然我已经完成了描述的步骤,但调试不工作。
  • 你能从这个扩展的状态栏中改变你的(虚拟)Python环境吗?它是否显示您的默认 Python 环境?
  • 是的。如果我使用全局python解释器,调试器可以工作。
【解决方案2】:

我认为问题在于您在 Windows 下运行,但您将 shell 设置为 bash。如果您使用的是 WSL,请查看包含 WSL 的 instructions on remote development。如果您使用的是 git-bash,请注意 Python 扩展不支持 git-bash 作为 shell。

【讨论】:

  • 安装最新版VS code后问题解决。
猜你喜欢
  • 2019-05-14
  • 1970-01-01
  • 2019-05-29
  • 2018-07-04
  • 2023-02-16
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 2020-04-04
相关资源
最近更新 更多