如何使用 PYTHONPATH 和 VSCode Python 扩展进行调试? [英] How to use PYTHONPATH with VSCode Python Extension for Debugging?

查看:41
本文介绍了如何使用 PYTHONPATH 和 VSCode Python 扩展进行调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个结构类似于

I'm working on a project which is structured like

Parent Directory
----+ MyPackage
     ----__init__.py
     ----file1.py
----+ Tests
     ----test.py

当我从终端运行测试时,我使用

When I run the tests from terminal, I use

PYTHONATH=./ python ./Tests/test.py

现在,当我在安装Python 扩展"后尝试调试选项时,会引发错误

Now, when I try the debug option after installing 'Python Extension', error is raised

Exception has occurred: ModuleNotFoundError
No module names 'MyPackage'

我怎样才能将 PYTHONPATH 放到调试配置中,这样它才会小心?

How can I put PYTHONPATH to the debug configuration such that it will taken care?

推荐答案

经过一些搜索和反复试验,我发现了一些有效的方法.我在这里发布它,以便寻找相同问题的人也可以尝试.我不确定这是否是正确的做法.

After some search and trial and error, I found something that works. I'm posting it here so that people looking for the same problem can also try. I'm not sure whether this is the right way to do t.

创建(或添加)一个文件 .vscode/settings.json 内容为

Create (or add to) a file .vscode/settings.json the contents as

{
    // .. any other settings
    "terminal.integrated.env.linux": {
        "PYTHONPATH": "${workspaceFolder}"
      }
}

现在我可以使用包运行我的项目了.

Now I'm able to run my project with the package.

这篇关于如何使用 PYTHONPATH 和 VSCode Python 扩展进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆