在vscode中调试时如何重写/更正pythonpath?

qltillow  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(208)

我在这个结构中有一个项目:

.
├── hacktcha
│   ├── cli.py
│   ├── conf.py
│   ├── generator
│   │   ├── base.py
│   │   └── __init__.py
│   ├── hacktcha.py
│   ├── __init__.py
│   └── server.py
├── poetry.lock
├── pyproject.toml
└── tests
    ├── __init__.py
    └── test_hacktcha.p

当我尝试通过以下launch.json配置调试cli.py时:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: CurrentFile",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

我得到了这个错误:

Exception has occurred: ModuleNotFoundError
No module named 'hacktcha.hacktcha'; 'hacktcha' is not a package

During handling of the above exception, another exception occurred:

  File "/apps/hacktcha/hacktcha/cli.py", line 4, in <module>
    from hacktcha.hacktcha import HacktchaLearner

在cli.py的开头添加一些调试代码:

print(sys.path)

sys.path.pop(0)
sys.path.insert(0, "/apps/hacktcha")

我得到的Python是:

['/apps/hacktcha/hacktcha', '/conda/envs/hacktcha/lib/python37.zip', '/conda/envs/hacktcha/lib/python3.7', '/conda/envs/hacktcha/lib/python3.7/lib-dynload', '/conda/envs/hacktcha/lib/python3.7/site-packages']

并且应用程序可以继续。
我的问题是,当vscode将错误的路径(“/apps/hacktcha/hacktcha”)注入pythonpath时?如何纠正这种行为?
我尝试在launch.json中添加pythonpath,如下所示:

"env": ["PYTHONPATH":"blahblah"]

这不起作用,因为错误的路径('/app/hacktcha/hacktcha')具有更高的优先级。
我想知道是否有人遇到过同样的事情,知道为什么以及如何解决?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题