搭建开发环境遇到了上述问题, 原本觉得很简单, 实际上倒腾了2-3小时, 在此作个记录.python
https://code.visualstudio.com...json
In VS Code, PYTHONPATH affects debugging, linting, IntelliSense, unit testing, and any other operation that depends on Python resolving modules. For example, suppose you have source code in a src folder and tests in a tests folder. When running tests, however, they can't normally access modules in src unless you hard-code relative paths. To solve this problem, add the path to src to PYTHONPATH.
能够看到PYTHONPATH会影响不少东西. 对开发影响最大的就是linting, IntelliSense, unit testing了. 我习惯了现代化IDE, 没有跳转总以为少了点什么.less
https://code.visualstudio.com...
默认是${workspaceFolder}/.env
我修改.vscode/settings.json为了${workspaceFolder}/.vscode/.env:this
{ ... "python.envFile": "${workspaceFolder}/.vscode/.env", ... }
.vscode/.envspa
PYTHONPATH=./your_src_dir:${PYTHONPATH}
donedebug
最大的坑点是不能使用绝对路径, 这里我没有看代码, 不能用绝对路径绝对是BUG:code
PYTHONPATH=${workspaceFolder}/your_src_dir:${PYTHONPATH}