Reputation: 2188
I have both anaconda and VS Code installed in my system. When I start writing a script, VS Code gives me an option to chose the interpreter. I choose my particular conda environment. This works fine. However when I try to run the script using Ctrl+Alt+N or using the play button on the top right (using the extension Code Runner), the terminal that opens in the VS Code doesn't recognize that I am now working in a conda environment.
As a result, it gives an error that the module is not installed (because the module is available only in the conda environment).
When I try to manually activate the conda environment from the VS Code terminal, it doesn't work.
What is the workaround? I am using Windows.
Update: If I use cmd
as the default integrated terminal in VS Code in place of PowerShell
, then the command activate NAME_OF_ANACONDA_ENV
works. And then, I can manually run the script. However, running the script using Ctrl+Alt+N still doesn't work; it doesn't recognize that I am in a conda env.
Upvotes: 3
Views: 4368
Reputation: 81
After a few tries i figured out how to do it. So, this works for me.
vs code settings search: code-runner.executorMap
Choose User
and
Edit in settings.json
find: "python": "python -u"
change: "python": "$pythonPath -u $fullFileName"
if you encounter tempCodeRunnerFile
or selection problem:
code-runner.ignoreSelection
Upvotes: 7
Reputation: 3936
On windows 10: Ctrl+Shift+P
and selecting the environment gets the job done.
After setting the environment, I execute by pressing Crtl+F5
to execute without debugging and F5
to debug.
Upvotes: -1