Issue
I have no trouble running and debugging my project with VSCode Python Extension (ms-python.python
), but since python sub-project root directory is not the whole project directory, all imports from my sources are underlined with red color and are listed in the problems
and so Go to definition
and some similar features don't work properly.
How can I tell the IDE where's the start point of my project:
Whole Project path:
docs
server
entities
user.py
customer.py
env
viewer
db
The server
directory is where the imports path are started from:
from entities.user import User
Solution
You can create a .env
file with:
PYTHONPATH=server
That will add your server
folder to PYTHONPATH
as needed.
(You may need to restart VSCode for it to take PYTHONPATH
into account correctly.)
Edited to clarify...
Create a file named .env
under the repo root e.g. your_repo/.env
.
Also creating the file under the folder where your consuming code is, instead of under repo root, seems to work e.g. your_repo/service/.env
.
For more details, see documentation on environment variable definition files.
For me this worked without restarting VSC, perhaps this is a matter of newer VSC and extensions versions.
Answered By - Brett Cannon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.