Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding to PYTHONPATH in VS Code

I'm trying to add the src folder to my PYTHONPATH i.E. do the same thing as Mark directory as sources root in PyCharm.

I've looked at the solutions to Visual Studio Code - How to add multiple paths to python path? but the solutions shown there do not work for me.

I've set up my minimal example as follows shown in the screenshot below:

enter image description here

My understanding would be that having a .env file with PYTHONPATH="./src;${PYTHONPATH}" would add the src file to the path.

Nevertheless, when running the code runner or when running python change_pyhton_path.py src is not part of the PYTHONPATH and the direct import from src fails.

I do have setting "python.envFile": "${workspaceFolder}/.env".

In pyCharm on the other hand everything works as it should after hitting Mark directory as source on src. enter image description here

Thanks for helping out!

like image 783
Hellvetia Avatar asked Feb 22 '20 17:02

Hellvetia


People also ask

How do I enter the interpreter path in VS Code?

To do so, press CMD + SHIFT + P , type Python, and choose Select Interpreter.


1 Answers

in your settings.json add:

"terminal.integrated.env.windows": {
    "PYTHONPATH": "full python path here"
}
like image 122
Szabolcs Dombi Avatar answered Sep 25 '22 01:09

Szabolcs Dombi