Configure your Python IDE to work with ArcMap and ArcGIS Pro’s ArcPy

October 31, 2018 Tom Thompson

With the increasing popularity of ArcGIS Pro, you may find yourself building Python scripts in both ArcMap and ArcGIS Pro on the same system. Sorting out which Python interpreter version to use can become confusing and frustrating, resulting in module and DLL errors. In this blog post, we’ll sort out how to understand when to use which Python interpreter version and configure an Integrated Development Environment (IDE) to easily switch between them when developing. Let’s learn how!

As ArcGIS Pro becomes more popular, developing scripts using ArcPy in both ArcMap and ArcGIS Pro will become more common. Both ArcMap and ArcGIS Pro installations come with their own Python interpreter (their own Python.exe). ArcMap uses Python version 2.x, and ArcGIS Pro uses Python 3.x. In addition to this, ArcMap’s default Python interpreter is 32bit, and ArcGIS Pro’s Python interpreter is 64bit. ArcMap also has a 64bit version installed with Background Geoprocessing. Confused yet? No problem, here’s a table to sort your thoughts.

ArcMap and ArcGIS Pro's Python interpreters and default locations.

Note that as of ArcGIS Pro 2.2, the default Python interpreter listed above is read-only and cannot have new modules installed within it. You'll have to create a clone, following our documentation on Cloning an Existing Environment, and then follow the guide below to point to that new cloned environment.

Why is it important to know and be able to distinguish between them? Because these interpreters have their own settings and paths which reference their own modules. These modules (such as ArcPy) are designed to work within a specific bit architecture and Python interpreter. What this means is that the ArcPy module which runs in your ArcGIS Pro will be different than the ArcPy which runs in your ArcMap, so referencing the correct interpreter is very important when developing and executing your scripts. If the incorrect one is selected when you run your script, it will very likely fail.

ArcMap’s Python 2.x interpreter and path variables.

ArcGIS Pro Python 3.x interpreter and path variables.

Now that we know why it is important to know which Python interpreter we’re building our scripts in and which one to reference when we run them, how do we set up our system to make moving between each of them simple? We can use an Integrated Development Environment (IDE). Specifically, we will configure PyCharm.

1. First, we’ll install an IDE, specifically PyCharm.

PyCharm is an IDE designed to work specifically with the Python language in both 2.x and 3.x. The community edition of PyCharm is a free, open-source IDE and is one of the most popular amongst Python developers. You can use your own preferred IDE and these same concepts apply, but lets move forward with PyCharm. Let’s download the community edition, run the installer and follow the requirements, installation and launching guide. Once installed, launch PyCharm.

PyCharm’s ‘Welcome to PyCharm’ splash screen.

2. Now that we have PyCharm downloaded and installed, we need to configure it to tell it which Python interpreters we have installed on our system.

We’ll start by selecting the Configure button in the bottom right corner of the splash screen and select Settings. This will bring us to the default settings of our PyCharm install. From here, we’ll select Project Interpreter on the left hand column.

PyCharm’s Project Interpreter Settings window.

From within the Project Interpreter options, select the drop-down arrow in the top right corner and select ‘Show all’ to bring up the list of project interpreters. This list will be empty, but we’ll populate it with some interpreters listed above.

Empty Project Interpreters window.

In the top right corner, select the green plus sign to add a new project interpreter. This will open the Add Python Interpreter window. On the left side of this window, select System Interpreter.

System Interpreters window.

PyCharm will list some of these interpreters automatically if they’re installed into well-known, standard directories. These will include our ArcMap python interpreters listed above, the 32bit and the 64bit versions (if you have Background Geoprocessing installed). Your path may be slightly different if ArcMap 10.6 was used in this example, but it will list your corresponding ArcMap version in the path to the python.exe. Select one of the ArcMap interpreters, and press OK. Do the same for the other ArcMap interpreter (if you have Background Geoprocessing installed). As you do this, you’ll see the interpreters listed in your Project Interprets window.

Lastly, we’ll want to add ArcGIS Pro’s Python 3.x Interpreter to the list of project interpreters. Do to this, we’ll again click the green plus sign in the top right corner and select System Interpreter. In the top right corner of the Add Python Interpreter window, we’ll choose the radio button (shift + enter) to open the file browser. In this window, we’ll browse to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\, select python.exe and then click OK. This will list ArcGIS Pro’s python interpreter in our Add Python Interpreter window where we’ll again click OK.

The PyCharm Project Interprets window showing ArcMap’s 32bit and 64bit and ArcGIS Pro’s 64bit interpreters.

In the Project Interpreter window, we will see each interpreter listed that we’ve added as interpreters. From here, we can select OK. This will bring us back to the Default Settings menu and will show each project interpreter, their corresponding modules, their version and available updates for each of those modules.

PyCharm’s Project Interpreter menu showing installed modules in ArcGIS Pro’s Python Interpreter.

3. We’ve configured PyCharm to reference ArcMap’s and ArcGIS Pro’s Interpreters and now we’ll start projects to reference these interpreters.

Now that we have configured PyCharm to use each of our interpreters, we can select these interpreters on a project-by-project basis or switch between them in the project as needed depending on which we want to run the script against. Let’s run PyCharm by visiting the Welcome to PyCharm splash screen and selecting Create New Project. In this window, we have the option to select our project interpreter by clicking on the down arrow beside the project interpreter listed for the new project.

 

New Project Interpreter options in PyCharm.

We’ll want to select the radio button for Existing Interpreter and, from the dropdown list, select the interpreter for the application we want to develop our script for. If we want to develop our script for ArcGIS Pro, we’ll choose Python 3.6. If we want to develop the script for ArcMap, we’ll choose one of the two Python 2.7 versions (if we have Background Geoprocessing installed). We’ll give our project a name and select Create. Now we can develop and test our script in that project with the appropriate python interpreter version, whether that be for ArcGIS Pro or ArcMap.

If you change your mind or want to test that project in another interpreter, changing it is quick and easy. Go to Settings and on the left hand side select Project Script and then Project Interpreter. This will list the current interpreter being used in the project; from the dropdown list, you can select any interpreter added as a project interpreter and change the project to use that version instead!

Now you’ve configured your IDE to use multiple different python interpreters installed with ArcGIS Pro and ArcMap. You’ve learned why it’s important to know which interpreter you’re coding within and how to quickly switch between them as needed in PyCharm. You’re ready to get developing! Good Luck!

 

About the Author

Tom Thompson

Tom Thompson is a Developer Support Analyst with Esri Canada’s Developer Support Team. He has a Bachelor of Science in Environmental Geoscience and Geomatics from the University of Guelph and a Graduate Certificate as a GIS Applications Specialist from Fleming College. Tom’s passion in GIS stems from his childhood spent exploring Ontario’s cottage country and his interest in technology. He hopes that his work in GIS will help to manage and care for the environment so that future generations can enjoy it as he does. In Tom’s day-to-day role, he provides support to clients who have implemented automation or customization of Esri software and applications.

More Content by Tom Thompson
Previous Article
10 things I like about ArcGIS Online
10 things I like about ArcGIS Online

ArcGIS Online is Esri’s powerful, web-based GIS. Discover 10 interesting capabilities that are worth explor...

Next Article
Customizing vector basemaps
Customizing vector basemaps

Learn about vector basemaps’ benefits and how to customize them to suit your needs.

×

Stay up to date with the Esri Canada Blog.

First Name
Last Name
Preferred Language
Education & Research- optional
Getting Technical- optional
News & Updates- optional
Spatial Data Infrastructure- optional
I agree to receive relevant electronic messages from Esri Canada.
Thank you.
Error - something went wrong!