PyCharm Setup for ArcGIS Desktop

849
5
12-10-2021 04:58 PM

PyCharm Setup for ArcGIS Desktop

PyCharm is a very useful Integrated Development Environment maintained by JetBrains that has become very popular for users wanting to develop Python for use with ArcGIS Pro. This document is an attempt to guide you to a trouble free installation set up for use with ArcGIS Pro (and ArcMap if you need to work in that environment as well).

PyCharm download and install

PyCharm Community Edition is free to download from www.jetbrains.com. The Community Edition has pretty much all you will need, the professional ($) edition is worth looking into if you need to code in JavaScript or SQL, it has many useful features for that kind of development. But for coding Python scripts, the free community edition is fine.

When you run the installer be sure not to click any of the boxes on the setup dialog, it's best to keep your Windows paths and settings "clean", to avoid messing with Windows settings on which other applications may be dependent.  We will be setting preferences within PyCharm to make it play well with ArcGIS.

pycharm_install.png

Configure Python interpreter for ArcGIS Pro

After PyCharm launches, click the gear at the upper right corner of the screen (or press Ctrl-Alt-S) to open the settings dialog. You can set up PyCharm with multiple Python interpreters, and we want to make the default setup for ArcGIS Pro (you can choose others though, which is handy!)

  1. Select Python Interpreter at left
  2. Click the gear icon at upper right and select Add
  3. Select the Existing environment radio button
  4. Click (set) Make available to all projects
  5. For Interpreter:  click the ... icon at right and navigate to and select the python.exe for Pro:
    C:\Program Files\ArcGIS\Pro\bin\Python\envs\argispro-py3\python.exe
  6. Click OK.

pycharm_arcgispro_setup.jpg

Configure Python interpreters for ArcMap (ArcGIS 10.x). 

Note this step is not needed if you aren't using ArcMap.

Repeat the steps from the last section to add the pythons for ArcMap:

  • ArcMap 32-bit: C:\Python27\ArcGIS10.8\python.exe
  • ArcMap 64-bit geoprocessing (if installed): C:\Python27\ArcGISx6410.8\python.exe

Now, when setting up a new PyCharm project, you can choose from the configured interpreters to get the environment you need for your project.

Configure PyCharm Terminal for ArcGIS Pro

PyCharm supports a terminal window for use in manipulating the conda environment, running shell tools, editors, or whatever else. The standard shell environment for ArcGIS Pro is the one you launch by with the Windows shortcut Python Command Prompt - which launches a shell with the proenv.bat script.

Bring up to the same settings dialog used above to set the Python interpreters

At left, find Tools > Terminal

For Shell Path: click the ... icon at right and navigate to and select 
C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat

Configuring PyCharm Terminal for ArcMap

(Thank you @AzinSharaf (see comments below). An Anaconda solution may be possible as well.)

1. Create a clone of the environment Python 2.7 x64 environment

C:\Python27\ArcGISx6410.8\python.exe -m virtualenv py27-clone-108

2. Copy ArcMap .pth files from C:\Python27\ArcGISx6410.8\ folder to the py27-clone-108 venv folder

3. For Terminal use this command to start a cmd.exe with the paths in place to run and manage python modules

C:\Windows\System32\cmd.exe /k "C:\Python27\envs\py27-clone-1081\Scripts\activate.bat"

 

Comments

@DanPatterson@DrewFlater - open to suggestions, I haven't seen a config guide and my students had a heck of a time getting this set up for the Python For Everyone course. So I made this attempt.

Sorry Curtis, I haven't used pycharm in ages. 

I have been using spyder installed in base using conda, but they now have installers which enable one to chose the python interpreter if they have other clones etc.  

Installation Guide — Spyder 5 documentation (spyder-ide.org)

mac, windows, linux

I don't see a major benefit of having python 2.x in pycharm terminal but you can do it with the following workflow.

1- clone python 2.7 environment

2- in the Pycharm terminal path enter:

C:\Windows\System32\cmd.exe /k "C:\Python27\envs\py27-clone-1081\Scripts\activate.bat"

then your Terminal would be like this:

AzinSharaf_0-1640135290129.png

 

There is no "clone" for ArcGIS 10x desktop python, it uses a basic standalone C Python system install, not a conda env.

You just need to point pycharm at the correct interpreter C:\Python27\ArcGIS10.[X]\python.exe

by "clone 2.7" I mean install virtualenv on default python2.x and create a new venv:

C:\Python27\ArcGISx6410.8\python.exe -m virtualenv py27-clone-108

and then copying PTH files to the new venv folder and then activate it. It works on my machine. 

 

Version history
Last update:
‎01-02-2022 11:18 AM
Updated by:
Contributors