How to set the root directory for Visual Studio Code Python Extension?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)