Skip to main content
These instructions refer to Anaconda Distribution exclusively, but will also work with Miniconda.
Visual Studio Code (VS Code) is a free, cross-platform source code editor that works with Anaconda Distribution and Miniconda. Installing the Python for Visual Studio Code extension enables VS Code to connect to a ’s version of Python as an interpreter for your Python code files.
More of a visual learner? Sign in to Anaconda.com and enroll in our Get Started with Anaconda course to learn to create a simple Python program with VS Code.

Creating a conda environment in VS Code

Before starting your Python project, Anaconda recommends creating a conda environment to isolate your project’s software packages and manage their dependencies.
You must have the Python for Visual Studio Code extension installed to create new conda environments from within VS Code on Windows.
If VS Code doesn’t display your conda environments, make sure at least one environment has Python installed. The base environment alone might not be sufficient for VS Code to detect conda. See Creating a new environment for details on creating environments with Python.
  1. Open the Command Palette by pressing Ctrl+Shift+P.
  2. Select Python: Create Environment…
  3. Select the environment type:
Creates a .conda environment in your workspace. Select the Python version to install in the environment.
If your new environment doesn’t appear in the interpreter list, open the Command Palette and run “Developer: Reload Window”, then try selecting the interpreter again.
Alternatively, you can create a new environment with Anaconda Prompt (Terminal on macOS/Linux), and then select the environment in VS Code as the workspace’s Python interpreter. For more information about Python environments in VS Code, see the official VS Code documentation.

Selecting Anaconda as a Python interpreter

Now that your conda environment has been created, select the environment as an interpreter. This ensures that your code has access to the correct Python version and packages installed in your conda environment.
  1. Open any Python file.
  2. Open the Command Palette by pressing Ctrl+Shift+P (Windows, Linux)/Cmd+Shift+P (macOS).
  3. Select Python: Select Interpreter.
  4. Select the conda environment you want to use. Conda environments appear with the environment name, Python version, and path (for example, hello-conda-env (3.12.13) ~/miniconda3/envs/hello-conda-env/bin/python).
You can also select Enter interpreter path… to browse to a Python interpreter manually. For more information on finding a specific interpreter path in your Anaconda installation, see Finding your Anaconda Python interpreter path. The selected interpreter appears in the bottom right corner of the status bar in VS Code. You can also click the interpreter in the status bar to change it.
VS Code status bar showing the selected conda environment as the Python interpreter in the bottom right corner

Adding packages to your environment

To add packages to your environment in VS Code:
  1. Open a new terminal by pressing Ctrl+`.
  2. Run the following command:
On Windows, you can run conda commands in both Powershell and Command Prompt terminals in VS Code.
VS Code on Windows showing conda install command running in PowerShell terminal
When you select the new environment, you might see a notification that says, “Selected conda environment was successfully activated, even though ‘(.conda)’ indicator may not be present in the terminal prompt.” You can still run conda commands in the terminal. See VS Code’s official documentation for more information on activating environments in terminal.
Learn more about adding conda packages to environments.

Testing your setup

You are now ready to run Python scripts in VS Code!
  1. Create a new Python (.py) file.
  2. Add the following code to your file:
  3. Save the file.
  4. Click Run Python File.
Arrow pointing to the Run Python File button in the VS Code toolbar
The terminal displays your output, confirming the script ran successfully with your conda environment’s Python interpreter:
The second line shows the Python version installed in your environment and confirms that Python was distributed by Anaconda, Inc. rather than from another source. For more information on working with Python in VS Code, see Python in Visual Studio Code.