Fail to plot in ArcGIS Pro Python

12-25-2020 02:30 AM
Labels (1)
New Contributor

When trying to plot using Seaborn module in the ArcGIS Pro (2.6) Python shell, I get an error from the tkinter package:

File "C:\Users\Sarah\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\tkinter\", line 2018, in __init__
baseName = os.path.basename(sys.argv[0])
IndexError: list index out of range

The minimum code that reproduces the error is as follows:

import tkinter


I tried updating the packages, but it doesn't solve the problem. When executing the same two lines of code outside ArcGIS Pro (directly from the python shell), there is no error. Hence, I assume it is an intrinsic ArcGIS Pro error.

4 Replies
MVP Esteemed Contributor

You are better off using Seaborn outside of the Pro's python shell.

I use Spyder Spyder 4 ... the python IDE for science - GeoNet, The Esri Community

It has many graphic options from inline to separate floating windows.

If your intent is to plot maps, then use the notebook within pro

... sort of retired...
New Contributor

Yes, that works, but I think it should be possible within ArcGIS Pro's Python shell.  

0 Kudos
MVP Esteemed Contributor

I don't know if the shell is tied to the base environment or it will use the cloned environment.

I suspect the python shell is somewhat limited in its capabilities and is intended for quick runs, or using Pro's graphic capabilities and not those of external modules.Since qt console is installed with jupyter, you can use it as a quick shell.  I just create a shortcut on the desktop.

C:\... install folder ...\bin\Python\envs\arcgispro-py3\pythonw.exe "C:\... install folder ...\bin\Python\envs\arcgispro-py3\Scripts\"

Start in
C:\... install folder ...\bin\Python\envs\arcgispro-py3

Although I tend to use Spyder or Notebook for most work

... sort of retired...
0 Kudos
Esri Contributor

@sarah-paradis  another option to the ones mentioned above would be to change the matplotlib backend.

Here, the issue is tkinter is not given a GUI window by ArcGIS Pro and it is receiving an empty list that it is trying to invoke GUI elements into. If you are okay with writing your matplotlib figures to local files, as opposed to pop-up figures, you can change the backend of the Python instance via:


import matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2,2, figsize=(15, 6))

Here subplots is just an example, you can call any figure you would like from here on out.


Here it is important to import matplotlib first and setting the backend to agg, before calling matplotlib.pyplot. If you import matplotlib.pyplot, it will set the backend to TkAgg and will not let you change the backend to agg. Once this is done, your matplotlib calls will not require pop-ups windows, that ArcGIS Pro will not allow, and you can create figures and write them to local files.