Home > Back-end >  how to change module path for python in visual studio code
how to change module path for python in visual studio code

Time:09-22

I'm sorry if this is trivial, but I'm just starting python and I don't know a lot of terminology so bear with me.

background information:

I just recently changed my IDE from anaconda (Spyder) to Visual Studio Code and I realized that a lot of modules that I installed from pip and used to able to import on Spyder is now unavailable on Visual Studio Code. The only work around that I have been able to come across is to import sys and append the appropriate path to every single one of my project. This is obviously very annoying and is quite a bit of a hassle every time I try to start a new project. Since Spyder works fine for me, I'm convinced that the problems lies in the Visual Studio Code settings instead. But every articles and advices I've came across couldn't give me a straight answer without throwing terminology that I'm unfamiliar with left and right.

Request:

Can anyone help me to permanently append a new python module path to Visual Studio Code so that I don't have to import sys every time?

Thanks in advance!

CodePudding user response:

You can use python interpreter path setting to point to a python installation/ venv

Set the path in .vscode/settings.json

{
    "python.defaultInterpreterPath": "path to python.exe"
}

You can follow enter image description here

Choose the environment where locates your needed modules as the interpreter then you may import them successfully without extra import sys.

More information please refer to Using Python Environments in VS Code.

  • Related