@Yossarian42's answer will work if you have a folder with your package name in the root of your project. However if your project follows the structure mentioned in Py-Pkgs and uses a src dir like:
mypkg
├── CHANGELOG.md ┐
...
├── pyproject.toml ┐
├── src │
│ └── mypkg │ Package source code, metadata,
│ ├── __init__.py │ and build instructions
│ └── mypkg.py ┘
└── tests ┐
└── ... ┘ Package tests
└── examples ┐
├── mypkg_examples.py │
└── ... ┘ Package examples
In this case, you use the following for dev.env in your workspaceFolder
(root):
PYTHONPATH=./src:${PYTHONPATH}
Create or edit {workspaceFolder}/.vscode/settings.json
with:
"python.envFile": "${workspaceFolder}/.env"
Full settings.json example:
{
"python.envFile": "${workspaceFolder}/dev.env"
}
For debugging the python.envFile
setting, you can print out the Python path with the following code:
import sys; print(f"sys.path: {sys.path}")