For projects that include external repos, it would be handy to insert the relative dependency paths ONLY when importing the necessary module.
Here is an example project layout:
Project root
+-- external repo/
+-- lib/
+-- config # defines Config class
+-- utils/
+-- mypackageA
+-- __init__.py
+-- app.py
main.py
In main.py, when an app instance that depends on the Config.py module in the external repo is created, the sys.path must include external repo/lib at the time of importing app:
from mypackageA import app
app.App()
Instead of setting the PYTHONPATH statically, an alternative is to modify sys.path in mypackageA.__init__.py by inserting paths to external repo/lib for the app module to import Config. However, vscode shows unresolved import warnings in this use case.
For projects that include external repos, it would be handy to insert the relative dependency paths ONLY when importing the necessary module.
Here is an example project layout:
In
main.py, when anappinstance that depends on theConfig.pymodule in the external repo is created, the sys.path must includeexternal repo/libat the time of importingapp:Instead of setting the PYTHONPATH statically, an alternative is to modify
sys.pathinmypackageA.__init__.pyby inserting paths toexternal repo/libfor theappmodule to importConfig. However, vscode showsunresolved importwarnings in this use case.