I have Anaconda working on my system and VsCode working, but how do I get VsCode to activate a specific environment when running my python script?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
The best option I found is to set the
python.venvPath
parameter in vscode settings to your anaconda envs folder.Then if you bring up the command palette (
ctl + shift + P
on windows/linux,cmd + shift + P
on mac) and typePython: Select Workspace Interpreter
all your envs will show up and you can select which env to use.The python extension will also need to be installed for the Select Workspace Interpreter option.
Note: The Select Workspace Interpreter takes around 10 seconds to come up on my computer using the current version of VSCode.
Simply use
I found a hacky solution replace your enviornment variable for the original python file so instead it can just call from the python.exe from your anaconda folder, so when you reference python it will reference anaconda's python.
so your only python path in env var should be like
If you need more details I don't mind explaining. :)
Unfortunately, this does not work on macOS. Despite the fact that I have
export CONDA_DEFAULT_ENV='$HOME/anaconda3/envs/dev'
in my .zshrc and"python.pythonPath": "${env.CONDA_DEFAULT_ENV}/bin/python",
in my VSCode prefs, the built-in terminal does not use that environment's Python, even if I have started VSCode from the command line where that variable is set.Although approved answer is correct, I want to show a bit different approach (based on this answer).
Vscode can automatically choose correct anaconda environment if you start vscode from it. Just add to user/workspace settings:
It works on Windows, macOS and probably Unix. Further read on variable substitution in vscode: here.
If you need an independent environment for your project: Install your environment to your project folder using the --prefix option:
In VSCode launch.json configuration set your "pythonPath" to: