Reputation: 21
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!
Upvotes: 2
Views: 6794
Reputation: 9521
Python extension has a function called Python: Select Interpreter, which you can get from Command Palette.
If you didn't create virtual environment when using Anaconda, modules should be installed globally, for example python3.9.5
.
If you installed modules in virtual environment, Python extension should also be able to detect and show them in the list by click the command Python: Select interpreter
. If not, you can manually Enter interpreter path
:
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.
Upvotes: -1