Python Code Runs in PyCharm But No Output

10521
10
01-06-2018 10:17 AM
EricWarner
New Contributor II

Hi,

    Learning ArcGIS Pro (2.0), as well as the new API.  I have been able to get Jupyter Notebooks going and run the sample code from index | ArcGIS for Developers  .  I wanted to use PyCharm as an alternative IDE to Jupyter and I have it also running.  I was able to run this section of code (from the NYC Cab demonstration notebook ) in PyCharm successfully, as indicated that it can back with a code of 0 .

import arcgis
from arcgis.gis import GIS

ago_gis = GIS() # Connect to ArcGIS Online as an anonymous user
search_subset = ago_gis.content.search("NYC_taxi_subset", item_type = "Feature Layer")
subset_item = search_subset[0]
subset_item

subset_map = ago_gis.map("New York, NY", zoomlevel=11)
subset_map


subset_map.add_layer(subset_item)

subset_feature_layer = subset_item.layers[0]

# query the attribute information. Limit to first 5 rows.
query_result = subset_feature_layer.query(where = 'OBJECTID < 5',
                                          out_fields = "*",
                                          returnGeometry = False)

att_data_frame = query_result.df # get as a Pandas dataframe
att_data_frame

However none of the maps were displayed nor the table, which gets loaded into the dataframe.  I have tried this code in a new Jupyter Notebook and the maps don't get displayed but the table does.  I'm wondering why the differences between the three IDE locations, in terms of the varying output.

Thanks,

Eric

0 Kudos
10 Replies
JoshuaBixby
MVP Esteemed Contributor

The answer to your question starts with knowing that the ArcGIS API for Python is built to work with, or includes components for, Jupyter Widgets (I believe GitHub - jupyter-widgets/ipywidgets: IPython widgets for the Jupyter Notebook specifically).  As the name entails, these widgets are part of Jupyter notebooks.

Before I go any deeper into explaining, how are you trying to run the code?  Interactively in the PyCharm console or running the code through an interpreter as part of a project?  What are you using for the project and console interpreters?

EricWarner
New Contributor II

Thanks for getting in touch.  I am running the code through an interpreter.  In PyCharm I opened a new project, and selected python.exe within the arcgispro-py3 environment (using the option within PyCharm to select an interpreter within a conda environment).  When I then view the properties of the selected interpreter, all of the packages associated with the arcgispro-py3 environment get listed.  I am very new to all of this so hopefully this addresses your question.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Spyder is part of the Anaconda distribution so is tightly integrated... I have a couple of blog post on it and how to set up Jupyter and IPython and Spyder... from the Pro package distribution.

https://community.esri.com/blogs/dan_patterson/2016/07/17/anaconda-spyder-and-arcgis-pro

https://community.esri.com/blogs/dan_patterson/2017/07/01/arcgis-pro-2-creating-desktop-shortcuts

and for the near future.... 

https://community.esri.com/blogs/dan_patterson/2017/02/10/python-36-what-is-new-in-the-anaconda-dist...

JoshuaBixby
MVP Esteemed Contributor

Whereas Jupyter has GitHub - jupyter-widgets/ipywidgets: IPython widgets for the Jupyter Notebook, there is no equivalent interactive HTML widgets for PyCharm.  That said, PyCharm does have  IPython/Jupyter Notebook Support - Help | PyCharm .  The path you will want to take involves configuring PyCharm to support the IPython/Jupyter that is installed with ArcGIS API for Python.  Improved Support for IPython interactive widgets in PyCharm has been put forward as a request by the PyCharm user community:  PY-14534 IPython Notebook interactive widgets support.

EricWarner
New Contributor II

Hi Dan and Joshua,

   Appreciate your insights. I will move on to Spyder and set it up according to the blog information.  I now have a better understanding of the limits of PyCharm.  Look forward to getting more familiar with ArcPro and the API.

Thanks,

Eric

0 Kudos
EricWarner
New Contributor II

The last things I will say about this problem is make a suggestion that ESRI edit the Getting Started section of the online documentation regarding the use of IDEs.  Specifically, on the page;

Python in ArcGIS Pro—ArcPy Get Started | ArcGIS Desktop 

Under the section;

Python IDEs

They should note that while many IDEs may work seamlessly with conda, they don't allow you to fully develop across the API.  It may be that ESRI doesn't want to have to keep up with all the recent IDE developments, and that is fine so long as they note that not all results represented in the notebook examples may be reproducible in some IDEs (here generating the output).  As it is they post a link to the Anaconda site, that lists "acceptable" IDEs and that is what most people will be running off of.  

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

so long as they note that not all results represented in the notebook examples may be reproducible in some IDEs (here generating the output).

To be fair the Sample Notebooks are just that, samples of code designed to be run with Jupyter notebooks, and the Samples web page does speak to how the sample notebooks are supposed to be used:

Samples

Samples presented here demonstrate various features of the ArcGIS API for Python. The samples are categorized by the user profile they are most relevant to. Most samples are in the form of a Jupyter Notebook, that can be viewed online, or downloaded and run interactively. A few samples are provided as stand-alone Python scripts in the accompanying GitHub SDK repository.

....

Next, extract the archive if you downloaded as an archive then open your terminal application and enter the directory with the samples. Then start Jupyter notebook application. Refer to section below for instructions on how to do this and to get yourself familiar with the notebook environment.

so long as they note that not all results represented in the notebook examples may be reproducible in some IDEs (here generating the output).

0 Kudos
EricWarner
New Contributor II

My contention is that the way the IDEs on the "getting started page" are presented dramatically understate the gap between the extent to which the sample code can be implemented versus how they are realized in the use of JN.  If Jupyter Notebooks is the only true end to end development environment for the API, they should just say so.  It would save new users significant time to know that not all (or maybe any of) the IDEs that they link to are in fact capable of providing the kind of end to end functionality that would make them  viable alternatives. The fact that you can't view output is a very significant short coming. Why even link to the Anaconda page with the IDE list? You just set people up for a lot of frustration.  I have been dealing with ESRI for a long time and unfortunately this is typical of how things roll with them.

0 Kudos
DanPatterson_Retired
MVP Emeritus

One of the reasons that I work with Spyder... it ships with Anaconda as does IPython and Jupyter.  

I have used many many before, you get used to them... The only thing I miss is code-folding, but it is on the way in Spyder 4, But I just fire up PythonWin when needed (old school, but still works in Anaconda with no problems)

0 Kudos