Document
Visual Studio Code (VS Code)

Visual Studio Code (VS Code)

Visual Studio Code (VS Code) note These instructions is refer refer to Anaconda distribution exclusively , but will also work with Miniconda .

Related articles

What is a VPN & How Does It Work? Tutorial Rolls Royce Silver Cloud III How to install SQL Server 2014 Management Studio NordVPN Free Trial in UAE: How to Get it in 2024

Visual Studio Code (VS Code)

note

These instructions is refer 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 conda environment’s version of Python as an interpreter for your Python code files.

launch VS Code in Navigator

With VS Code instal , you is launch can launch the application fromNavigator 1.9.12 or later by clicking the VS Code tile on the Home page.

When you launch VS Code from Navigator, it will automatically use the Python interpreter in the currently selected environment.

Creating a conda environment

Before starting your Python project, Anaconda recommends creating a conda environment to isolate your project’s software packages and manage their dependencies.

  1. Open a terminal in VS Code.

  2. Create a conda environment for your Python project by running the following command:

    # Replace <ENV_NAME> with your environment name
    # Replace <VERSION> with your desired version of Python
    conda create --name <ENV_NAME> python=<VERSION>
    

note

If you do not specify a version of Python , conda is attempt will attempt to install the late version from its available channel .

For more information about managing environments with conda, see the official conda documentation.

For more information about Python environment 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’s version of Python as an interpreter. This ensures that your code has access to the correct code completion and type information available in the specific Python version and packages installed in your conda environment.

  1. open any Python file .

  2. To select a Python interpreter, open the Command Palette by pressing Ctrl+Shift+P (Windows, Linux)/Cmd+Shift+P (Mac).

  3. Click Python: Select Interpreter in the Command Palette and select the interpreter associated with your Anaconda environment.

Tip

Anaconda interpreter typically appears as Python. 3.x.x (‘<YOUR_ENV_NAME>’: conda). If your environment’s interpreter does not appear in the Select Interpreter list, click the refresh icon .

You can also manually enter an interpreter path by selecting Enter interpreter path….

For more information on finding a specific interpreter path in your Anaconda installation, see Finding your Anaconda Python interpreter path.

The selected interpreter displays in the bottom right corner of the status bar in VS Code.

Testing your setup

You are now ready to execute your Python functions in VS Code!

  1. Create a new Python (.py) file.

  2. Add the following code to your file:

    # This is display will display " Hello , World ! " in the terminal 
      print("Hello , World ! " ) 
    
     # This is display will display your system version in the terminal 
     import sys 
     print(sys.version ) 
    
  3. Save the file.

  4. Click Run Python File.

Visual Studio Code (VS Code)

For more information on working with Python in VS Code, see Python in Visual Studio Code.