Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
`.venv`在Windows下的VSCode中调试Python时被忽略_Python_Visual Studio Code_Vscode Debugger_Python Venv - Fatal编程技术网

`.venv`在Windows下的VSCode中调试Python时被忽略

`.venv`在Windows下的VSCode中调试Python时被忽略,python,visual-studio-code,vscode-debugger,python-venv,Python,Visual Studio Code,Vscode Debugger,Python Venv,我在Windows中有一个Python项目,它通过console\u script提供一个命令行应用程序。Python包在/.venv中使用了一个poetry virtualenv,并以可编辑模式安装到venv中 现在,我想在集成VSCode终端中调试命令行应用程序。为了做到这一点,我创建了一个launch.jsonconfig,如下所示: { // Use IntelliSense to learn about possible attributes. // Hover to

我在Windows中有一个Python项目,它通过
console\u script
提供一个命令行应用程序。Python包在
/.venv
中使用了一个poetry virtualenv,并以可编辑模式安装到venv中

现在,我想在集成VSCode终端中调试命令行应用程序。为了做到这一点,我创建了一个
launch.json
config,如下所示:

{
    // 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: Device Agent (WLAN)",
            "type": "python",
            "request": "launch",
            "program": "mvp-end-device-agent",
            "args": ["<", "-r", "D:\\MassHunter\\Data\\demo_0000.d"],
            "console": "integratedTerminal"
        }
    ]
}
未成功地将其复制到项目本地
.vscode/settings.json
文件


如何修复或解决此问题?

这不是错误。默认的终端前缀应该是
PS\当前工作目录\
,因此当我们开始调试时,它将打开一个显示默认前缀的新终端实例。但是,当我们查看其执行脚本时:


第一个是
.venv\python.exe
,我们选择它作为解释器,调试完成后,环境被激活。然后您再次选择调试,此终端将保持.venv被激活。

结果表明,问题与venv管理无关,而是与如何处理控制台脚本有关。调试:

@panagiotis kanavos您认为这是VSCode中的错误吗?您是否尝试过像这样手动激活venv:,然后通过
python filename.py执行项目
?venv的激活没有问题。它可以自动工作,也可以手动工作。但是,如果运行调试器,将创建一个新的终端实例,并且需要激活venv作为调试器+venv管理器集成的一部分。您的解决方案是w.r.t.Python模块。不过,我有一个
控制台脚本。问题是我错误地解释了“程序”也适用于可执行文件,现在解决了:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.


PS D:\mvp-end-device-agent>  & 'd:\mvp-end-device-agent\.venv\Scripts\python.exe' 'c:\Users\Plasmion\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '58875' '--' 'mvp-end-device-agent' '<' '-r' 'D:\MassHunter\Data\demo_0000.d'
Traceback (most recent call last):
  File "d:\python\python386\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "d:\python\python386\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\Users\Plasmion\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\Plasmion\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\Plasmion\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "d:\python\python386\lib\runpy.py", line 264, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "d:\python\python386\lib\runpy.py", line 234, in _get_code_from_file
    with io.open_code(decoded_path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\mvp-end-device-agent\\mvp-end-device-agent'
PS D:\mvp-end-device-agent> & d:/mvp-end-device-agent/.venv/Scripts/Activate.ps1
(.venv) PS D:\mvp-end-device-agent>
{
    "python.pythonPath": "${workspaceFolder}/.venv/Scripts/python.exe"
}