Search code examples
pythonvisual-studio-codecondaenvironmentinterpreter

How do I access my conda packages in VS Code?


I am using VS Code for the first time, trying to run a .py file. However it is struggling to find the packages I have in conda (no virtual env, just base).

I have changed the Python interpreter so that it's now using "...64-bit (conda)".

I have also added "python.defaultInterpreterPath": "C:\\Users\\username\\anaconda3\\python.exe" into the JSON settings.

When I then run the file, it finds some packages but not all: it finds os, random and collections but not any others...

Also when I run print(sys.executable) I get "C:\Users\username\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe". I think this should instead be pointing towards the python.exe in anaconda3...

Any assistance with accessing my packages in conda would be appreciated!


Solution

  • As always, read the docs:
    https://code.visualstudio.com/docs/python/environments#_create-a-conda-environment It contains several hints of what can go wrong with conda environments in VSCode.

    Most important for you: A conda environment has to activated before you can use it and obviously this is not happening in your case. The terminal must show a (base) or (Anaconda3) on the prompt. Just pointing to the python.exe is not good enough.