Activating Anaconda Environment in VsCode

I have Anaconda working on my system and VsCode, but how do I get VsCode to activate a specific environment when I run my python script?

+33
source share
9 answers

If Anaconda is your default Python installation, then it just works if you install the Microsoft Python extension .

The following should work regardless of the Python editor, or if you need to point to a specific installation:

In settings.json, edit python.path with something like

"python.pythonPath": "C:\\Anaconda3\\envs\\py34\\python.exe"

Instructions for editing settings.json

+26
source

  1. shift + cmd + P

pyhton: Select Interpreter

  1. , , conda Python

Activating conda virtual environment

  1. , .
+34

, , - python.venvPath vscode anavonda envs.

"python.venvPath": "/Users/[...]/Anaconda3/envs"

, (ctl + shift + P windows/linux, cmd + shift + P mac) Python: Select Workspace Interpreter, envs , , env .

+11

, ( ).

Vscode anaconda, vscode. / :

{
    "python.pythonPath": "C:/<proper anaconda path>/Anaconda3/envs/${env:CONDA_DEFAULT_ENV}/python"
}

Windows, MacOS , , Unix. vscode: .

+10

, macOS. , export CONDA_DEFAULT_ENV='$HOME/anaconda3/envs/dev' .zshrc "python.pythonPath": "${env.CONDA_DEFAULT_ENV}/bin/python", VSCode, Python, VSCode , ​​ .

+6

python.pythonPath VSCode settings.json , . Anaconda Microsoft Visual Studio ( VS):

VS Code Navigator, VS Code Python .

Anaconda navigator

+4

: -prefix:

conda create --prefix C:\your\workspace\root\awesomeEnv\ python=3

VSCode launch.json "pythonPath":

"pythonPath":"${workspaceRoot}/awesomeEnv/python.exe"
+2

python, python.exe anaconda, , python, anaconda python.

, Python env var :

"C:\Anaconda3\envs\py34\", or wherever the python executable lives

, . :)

0

: https://code.visualstudio.com/docs/python/environments#_conda-environments

As noted earlier, the Python extension automatically detects existing conda environments, provided that the environment contains a Python interpreter. For example, the following command creates a conda environment with a Python 3.4 interpreter and several libraries that VS Code displays in the list of available interpreters:

 conda create -n env-01 python=3.4 scipy=0.15.0 astroid babel 

On the contrary, if you were unable to specify an interpreter, as in the case of conda create --name env-00, the environment will not appear in the list.

0
source

All Articles