Reputation: 2476
I have a project with the following folder layout:
app/ #actual python aplication code
|-- package1/
|-- __init__.py
|-- Class1.py
|-- package2/
|-- __init__.py
|-- Class2.py
|-- app.py # application entrypoint
venv/ #virtenv generated from python3
Dockerfile #release dockerfile
Everything works fine from the image generated via Dockerfile
running python app.py
and I can execute and debug the application from inside VSCode simply by right-clicking on app.py
and choosing the appropriate command.
Buuuut,VSCode is showing a warning message about unresolved import
as app.py
. The relevant app.py
code snippet is as follows
import package1
import package2
Nothing breaks, everything runs fine. It just seems to me that VSCode doesn't understand that app.py
is not at the root folder, so the python interpreter should not try to import from the root folder. Is there any configuration I am missing?
Upvotes: 0
Views: 501
Reputation: 15980
The issue is whatever tool is warning you about your imports doesn't know that app
is the anchor point for your code and not ../app
as you opened as your workspace. You will need to either open app
as your workspace or tell the extension that app/
is where Python should start looking (typically via PYTHONPATH
in a .env
file).
Upvotes: 1