Skip to main content

How to configure Visual Studio Code with ArcGIS Pro’s Python Environment

Want to know how to get started with writing Python code for your ArcGIS workflows? Here’s how you can get started by using Visual Studio Code as your IDE.

ArcGIS API for Python and ArcPy are both popular Python libraries for GIS users interested in automating workflows. However, to start programming and writing scripts for GIS workflows, an Integrated Development Environment (IDE) is highly recommended. This blog post will teach you how to configure your VS Code for ArcGIS Python development. VS Code is a popular IDE for developers due to its available extensions, IntelliSense code completion, and its general ability to work with other programming languages. If you are new to programming and have ArcGIS Pro installed, this article is for you!

Note: This is not an official recommendation from Esri Canada to use VS Code, but an example of how you can configure your IDE to work with Python environments in ArcGIS Pro.

1. Download Visual Studio Code (VS Code)

The first step is to download Visual Studio Code from the official website. After downloading VS Code, run the application as an administrator and install the program using the default settings.

Picture showing official site page for Visual Studio CodeOfficial site page for Visual Studio Code

2. Launch VS Code and Install the Python Extension

After successfully installing the program. Launch VS Code and it should bring you to the following interface like shown below. Don’t worry if your application doesn’t look exactly like the following picture:

View of VS Code after successful installation A view of VS Code after successful installation

On the leftmost bar, click the last icon at the bottom and search for Python. Install the extension. You might see that it installs multiple extensions at once and that is OK.

A picture of how to install the Python Extension using Visual Studio Code

Installing Python Extension in VS Code

Note: You may get an error message saying Python is not installed. VS Code does not know Python is installed with ArcGIS Pro. So, we need to specify where the Python interpreter is located in the next step.

A banner of an error message saying Python is not installed.

VS Code Python Warning Error Message

3. Change your Python Interpreter back in VS Code

Press Control + Shift + P and search for “>Python: Select Interpreter”.

The following command palette will drop down, and you should see something like this following screenshot. Choose the first option when it says, “Enter interpreter path…”:

A screenshot indicating to select “Enter interpreter path” on the command palette interface.

Then click “Find...”, which will result in the following window:

A screenshot indicating to select “Find” on the command palette interface.

4. Locate your ArcGIS Pro Python Interpreter

To find your interpreter in its default location, go to the following path using the File Explorer:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\

After navigating to this folder, select the python.exe interpreter and click “Select Interpreter”.

A screenshot showing the directory location of ArcGIS Pro’s Python Interpreter

The directory location of ArcGIS Pro’s Python Interpreter

If you are using ArcGIS Pro 2.9 and above, this interpreter will be a Python 3.7.x installation.

Note: If you have cloned environments in ArcGIS Pro, you are also able to find your specific Python Interpreter at C:\Users\<user>\AppData\Local\ESRI\conda\envs. For more information, please see tips below for cloning Python environments in ArcGIS Pro. 

5. Check that you have selected the right interpreter.

Click File > New File… > Select “Python File”

A screenshot showing how to create a Python File from the Command Palette.

You should now be able to see the right python interpreter selected looking at the bottom bar.

A screenshot showing verifying the location of the python interpreter.

If you hover above the part where it says ‘arcgispro-py3’ and you see the correct path, then you are set for some coding!

Tips & Tricks:

Cloning Python Environments

If you are planning to make changes to your ArcGIS Pro Python environment, clone your default environment. The default Python Interpreter and environment is not meant to be modified and you may see unexpected and undesired behaviours. Please visit the following links for more information:

Work with Python environments

How To: Clone a Python environment with the Python Command Prompt

Default Editor for Python Scripts in ArcGIS Pro

If you are working with scripts in ArcGIS Pro’s toolboxes, you can edit your scripts in VS Code after setting it as the default program for opening Python files. If you prefer using other IDEs or editors, this workflow applies too.

A screenshot showing how to change the default app for a Python file.

One way to change the default program is to use the right click menu from the Python file. 

A screenshot showing the edit option in a scripted tool in ArcGIS Pro opens VS Code by default.

When you edit the scripts in toolboxes, it will launch the default program to edit your Python files.

This post was translated to French and can be viewed here.

About the Author

Jim Wei is a GIS Developer with Esri Canada’s Core Technologies team. He focuses on creating applications using the Esri technology stack and customizes them with programming. Jim has a Bachelor of Science in Geoscience from the University of Toronto and a Graduate Certificate for GIS Applications from Fleming College. He has a keen interest in application development and programming. When Jim is not working, he flies his mini drone or makes delicious barbecue.

Profile Photo of Jim Wei