搭建開發環境遇到了上述問題, 原本覺得很簡單, 實際上倒騰了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}