简体   繁体   English

Python:无法在虚拟环境中使用vs代码进行调试

[英]Python: Cannot debug using vs code using virtual environment

I set up a python virtual environment named "myenv" in my project. 我在项目中设置了一个名为“ myenv”的python虚拟环境。 Then, I try to debug the script from VS code. 然后,我尝试从VS代码调试脚本。

Here is the output. 这是输出。 Please give some insights. 请提供一些见解。 Thanks 谢谢

    $ 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) 

My launch json looks like below. 我的启动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"
    }
  ]
}

If you install and use Python Extension from Microsoft then you can just start VS Code from your project root folder: code . 如果您安装并使用Microsoft的Python Extension ,则只需从项目根文件夹code .即可启动VS Code code . Then open some Python source file and in the lower left corner at the bottom status bar of VS Code you will see your current Python execution environment. 然后打开一些Python源文件,在VS Code底部状态栏的左下角,您将看到当前的Python执行环境。 You can click and change it by selecting your environment from the list. 您可以通过从列表中选择环境来单击并更改它。

I think the problem is you are running under Windows but you set your shell to bash. 我认为问题是您在Windows下运行,但是将shell设置为bash。 If you're using WSL then please see the instructions on remote development which includes WSL. 如果您使用的是WSL,请参阅有关远程开发说明,其中包括WSL。 If you're using git-bash then please note the Python extension does not support git-bash as a shell. 如果您使用的是git-bash,请注意Python扩展程序不支持将git-bash用作外壳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM