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

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

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

  1. .
  2. ├── hacktcha
  3. ├── cli.py
  4. ├── conf.py
  5. ├── generator
  6. ├── base.py
  7. └── __init__.py
  8. ├── hacktcha.py
  9. ├── __init__.py
  10. └── server.py
  11. ├── poetry.lock
  12. ├── pyproject.toml
  13. └── tests
  14. ├── __init__.py
  15. └── test_hacktcha.p

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

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "Python: CurrentFile",
  6. "type": "python",
  7. "request": "launch",
  8. "program": "${file}",
  9. "console": "integratedTerminal"
  10. }
  11. ]
  12. }

我得到了这个错误:

  1. Exception has occurred: ModuleNotFoundError
  2. No module named 'hacktcha.hacktcha'; 'hacktcha' is not a package
  3. During handling of the above exception, another exception occurred:
  4. File "/apps/hacktcha/hacktcha/cli.py", line 4, in <module>
  5. from hacktcha.hacktcha import HacktchaLearner

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

  1. print(sys.path)
  2. sys.path.pop(0)
  3. sys.path.insert(0, "/apps/hacktcha")

我得到的Python是:

  1. ['/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,如下所示:

  1. "env": ["PYTHONPATH":"blahblah"]

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

暂无答案!

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

相关问题