> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Visual Studio Code (VS Code)

export const Comments = ({children}) => {
  return <div class="my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border border-zinc-500/20 bg-zinc-50/50 dark:border-zinc-500/30 dark:bg-zinc-500/10" data-callout-type="comments">
      <div class="w-4">
        <svg width="14" height="14" viewBox="0 0 640 640" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" aria-label="Comments">
            <path d="M320 112C434.9 112 528 205.1 528 320C528 434.9 434.9 528 320 528C205.1 528 112 434.9 112 320C112 205.1 205.1 112 320 112zM320 576C461.4 576 576 461.4 576 320C576 178.6 461.4 64 320 64C178.6 64 64 178.6 64 320C64 461.4 178.6 576 320 576zM280 400C266.7 400 256 410.7 256 424C256 437.3 266.7 448 280 448L360 448C373.3 448 384 437.3 384 424C384 410.7 373.3 400 360 400L352 400L352 312C352 298.7 341.3 288 328 288L280 288C266.7 288 256 298.7 256 312C256 325.3 266.7 336 280 336L304 336L304 400L280 400zM320 256C337.7 256 352 241.7 352 224C352 206.3 337.7 192 320 192C302.3 192 288 206.3 288 224C288 241.7 302.3 256 320 256z" />
        </svg>
      </div>
      <div class="text-sm prose min-w-0 w-full">
        {children}
      </div>
    </div>;
};

<Note>
  These instructions refer to Anaconda Distribution exclusively, but will also work with Miniconda.
</Note>

[Visual Studio Code (VS Code)](https://code.visualstudio.com) is a free, cross-platform source code editor that works with Anaconda Distribution and Miniconda. Installing the [Python for Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) enables VS Code to connect to a <Tooltip tip="An isolated folder containing specific conda packages and dependencies that won't interfere with other projects. Each environment maintains its own versions of libraries and packages, so changes in one environment don't affect others.">conda environment</Tooltip>'s version of Python as an interpreter for your Python code files.

<Tip>
  More of a visual learner? [Sign in to Anaconda.com](https://auth.anaconda.com/ui/login?return_to=https://anaconda.com/app/) and enroll in our Get Started with Anaconda course to learn to [create a simple Python program with VS Code](https://learning.anaconda.com/courses/take/get-started-with-anaconda/lessons/63332024-create-a-simple-python-program-in-vs-code).
</Tip>

## 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.

<Note>
  You must have the [Python for Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) 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](/docs/getting-started/working-with-conda/environments#creating-an-environment) for details on creating environments with Python.
</Note>

<Tabs>
  <Tab title="Windows">
    1. Open the Command Palette by pressing Ctrl+Shift+P.
    2. Select *Python: Create Environment...*
    3. Select the environment type:

    <Tabs>
      <Tab title="Conda">
        Creates a `.conda` environment in your workspace. Select the Python version to install in the environment.
      </Tab>

      <Tab title="Venv">
        Creates a virtual environment using Python's built-in `venv` module. Select a Python installation to use, or select *Enter interpreter path...* to browse to one on your file system.
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="macOS/Linux">
    1. Open the Command Palette by pressing Ctrl+Shift+P (Linux)/Cmd+Shift+P (macOS).
    2. Select *Python: Create Environment...*
    3. Select the project, folder, or script you want to create the environment for.
    4. Click **OK**.
    5. Select the environment manager option that best fits your needs:

    <Tabs>
      <Tab title="Quick Create">
        Creates a `.conda` environment in your workspace automatically using the current Python version and installs any workspace dependencies found in your project.
      </Tab>

      <Tab title="Conda">
        Creates a conda environment. Continue with the following steps:

        1. Select the environment type:
           * **Named**: Creates a globally accessible named environment stored in your conda environments directory.
           * **Prefix**: Creates an environment in your current workspace folder.
        2. Select the Python version to install in the environment.
        3. Enter a name for the environment and press Enter twice to confirm.
      </Tab>

      <Tab title="Global">
        Uses your system-wide Python installation rather than an isolated environment.
      </Tab>

      <Tab title="venv">
        Creates a virtual environment using Python's built-in `venv` module. Continue with the following steps:

        1. Select a Python interpreter for the environment.
        2. Enter a name for the environment (the default is `venv`) and press Enter to confirm.
      </Tab>

      <Tab title="Enter Interpreter Path">
        Browse to and select a Python interpreter from anywhere on your system.
      </Tab>
    </Tabs>
  </Tab>
</Tabs>

<Tip>
  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.
</Tip>

Alternatively, you can [create a new environment](/docs/getting-started/working-with-conda/environments#creating-an-environment) with Anaconda Prompt (Terminal on macOS/Linux), and then select the environment in VS Code as the workspace's [Python interpreter](#selecting-anaconda-as-a-python-interpreter).

For more information about Python environments in VS Code, see the [official VS Code documentation](https://code.visualstudio.com/docs/python/environments).

## 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](/docs/getting-started/working-with-conda/ides/python-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.

<Frame>
  <img src="https://mintcdn.com/anaconda-29683c67/Qt6dsOjuOpG6LGMJ/images/VSC_python_interpreter.png?fit=max&auto=format&n=Qt6dsOjuOpG6LGMJ&q=85&s=8d09ed2224447aa62639a09bf53cbf64" alt="VS Code status bar showing the selected conda environment as the Python interpreter in the bottom right corner" width="3460" height="956" data-path="images/VSC_python_interpreter.png" />
</Frame>

## 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:

```sh theme={null}
conda install <PACKAGE_NAME>
```

<Comments>
  Replace \<PACKAGE\_NAME> with the name of the package you want to install.
</Comments>

<Note>
  On Windows, you can run conda commands in both Powershell and Command Prompt terminals in VS Code.

  <Frame>
    <img src="https://mintcdn.com/anaconda-29683c67/kBuj3mPdZoBk8YoG/images/vscode-package-install.png?fit=max&auto=format&n=kBuj3mPdZoBk8YoG&q=85&s=94abfc4edc20aa693880de0080b9d29f" alt="VS Code on Windows showing conda install command running in PowerShell terminal" width="2238" height="438" data-path="images/vscode-package-install.png" />
  </Frame>

  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](https://github.com/microsoft/vscode-python/wiki/Activate-Environments-in-Terminal-Using-Environment-Variables).
</Note>

Learn more about adding [conda packages](/docs/getting-started/working-with-conda/packages/install-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:

   ```python theme={null}
   # This will display "Hello, World!" in the terminal
   print("Hello, World!")

   # This will display your system version in the terminal
   import sys
   print(sys.version)
   ```

3. Save the file.

4. Click <Icon icon="play" iconType="regular" /> **Run Python File**.

<Frame>
  <img src="https://mintcdn.com/anaconda-29683c67/Qt6dsOjuOpG6LGMJ/images/VSC_python_run.png?fit=max&auto=format&n=Qt6dsOjuOpG6LGMJ&q=85&s=8802b8a096e02c4fd77a5e1fd185b3fd" alt="Arrow pointing to the Run Python File button in the VS Code toolbar" width="3460" height="990" data-path="images/VSC_python_run.png" />
</Frame>

The terminal displays your output, confirming the script ran successfully with your conda environment's Python interpreter:

```
Hello, World!
3.x.x | packaged by Anaconda, Inc. | ...
```

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](https://code.visualstudio.com/docs/languages/python).
