Code working in ArcGIS Pro Python Window but not in Spyder

6014
32
07-30-2019 06:16 PM
ThomasBlankinship
New Contributor

Like many of you, I want to be able to edit and execute python code from Spyder instead of ArcGIS's Python Window. I am running into some problems and hoping that someone can help me troubleshoot what exactly is going on. I noticed that some old scripts that I had written would no longer execute in Spyder but when the code was copied into ArcGIS Pro's Python Window the code worked just fine. After messing around with it for quite some time, uninstalling and reinstalling both ArcGIS Pro and Anaconda3 Navigator (3.7 64-bit), to not avail I decided to roll uninstall both again, delete all traces of them from my system, delete registry keys, etc. to make sure it wasn't the fault of something latent on my computer after uninstalling.

I just got everything reinstalled and am running into the exact same problem. Again, the code will work when copy pasted into the Python Window in ArcGIS Pro, but not in Spyder. Here is how I installed it after my clean uninstall:

1) Installed ArcGIS 2.3

2) Installed Patched 2.3.1, 2.3.2, and 2.3.3 in that order (I'm wary of 2.4 and know my code was working on 2.3)

3) Opened ArcGIS, signed in, went to Project --> Python --> Manage Environments --> Clone Environment

4) Once the Cloned Environment (named arcgispro-py3-clone) finished installing I closed ArcGIS Pro and restarted it

5) Went back into Project --> Python --> Manage Environments and changed the environment to the cloned environment

6) Checked that my sample code worked in the cloned environment in the Python Window, it did

7) Installed the spyder package (which installed all of its dependencies)

😎 Restarted ArcGIS Pro, checked that spyder package was installed, tried code again in Python Window, it worked

9) Installed Anaconda3 -> unchecked Anaconda3 as default Python 3.7, did not add to path

10) Opened Anaconda3 and checked for cloned arcgispro-py3 environment, it was there

11) Restarted computer for good measure

12) In Anaconda3, switched to arcgispro-py3-clone environment and launched spyder

13) Opened and ran my test code

Here is the error given to me by Spyder:

runfile('G:/My Drive/Python Scripts/polyline_to_polygon.py', wdir='G:/My Drive/Python Scripts')
Traceback (most recent call last):

File "<ipython-input-1-210cd50e08ec>", line 1, in <module>
runfile('G:/My Drive/Python Scripts/polyline_to_polygon.py', wdir='G:/My Drive/Python Scripts')

File "C:\Users\Tab5a\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)

File "C:\Users\Tab5a\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "G:/My Drive/Python Scripts/polyline_to_polygon.py", line 27, in <module>
ap.CopyFeatures_management(vtx_arr, vtx_output)

File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 2624, in CopyFeatures
raise e

File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 2621, in CopyFeatures
retval = convertArcObjectToPythonObject(gp.CopyFeatures_management(*gp_fixargs((in_features, out_feature_class, config_keyword, spatial_grid_1, spatial_grid_2, spatial_grid_3), True)))

File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))

RuntimeError: Object: Error in executing tool

I'm hoping I left out a step or something of that nature akin to forgetting to copy the batch files in ArcMap, but otherwise I have no clue why this wouldn't be working. Thank you all for your time and help.

0 Kudos
32 Replies
DanPatterson_Retired
MVP Emeritus

I new I saw it

FAQ: What are the reserved words for Esri's file geodatabase? 

But whether the case of the word is important is another question

0 Kudos
TonyDaSilva1
Occasional Contributor

Granted "update" is a reserved word. The problem still remains.

>>> import arcpy
>>> fc = "E:\Data\TEST\test.gdb\testa"
>>> arcpy.AddField_management(fc, "zzas", "TEXT")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 3899, in AddField
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 3896, in AddField
    retval = convertArcObjectToPythonObject(gp.AddField_management(*gp_fixargs((in_table, field_name, field_type, field_precision, field_scale, field_length, field_alias, field_is_nullable, field_is_required, field_domain), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
DanPatterson_Retired
MVP Emeritus

Time to do a Tech Support call.

It might not get resolved otherwise

TonyDaSilva1
Occasional Contributor

Can you confirm ArcGIS Pro 2.4 Python API is working as expected from outside the application?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Now notice my 'lark' comment.

I just did this in IDLE, and used "Update" as the field to add.

Now notice that an underscore was added the field name.   

ArcGIS Pro 2.4, python 3.6.8

If you want I can try it in Spyder, 

I even deleted the field

>>> arcpy.DeleteField_management(in_fc, "Update_")
<Result 'C:\\Git_Dan\\npgeom\\npgeom.gdb\\Polygons'>
>>> [f.name for f in arcpy.ListFields(in_fc)]
['OBJECTID', 'Shape', 'CENTROID_X', 'CENTROID_Y', 'INSIDE_X', 'INSIDE_Y',
 'Parts', 'Points', 'Curves', 'Shape_Length', 'Shape_Area']

PS.   I don't use the Python window in Pro... It is IDE-like, but not sure about its origins or what it is running, but I keep one or more python IDE open when I am working with pro.

Spyder, Pythonwin, Jupyter QtConsole, IDLE and even Jupyter Lab if you are feeling webby

0 Kudos
MichaelVolz
Esteemed Contributor

Dan:

I have a simple script based on your sample where I import arcpy, reference a feature class from a network location, and then I call ListField on the feature class.  Although spyder used from the Pro Add Package location recognizes the arcpy module, it says model arcpy has no attribute ListField.  Any idea why this would occur?

0 Kudos
DanPatterson_Retired
MVP Emeritus

perhaps "ListFields" not "ListField"

0 Kudos
MikePianka
New Contributor II

We are experiencing this same problem on some workstations. Arcpy works as expected in Pro's window, but running any arcpy tools in IDLE results in the error:

RuntimeError: Object: Error in executing tool
0 Kudos
ThomasBlankinship
New Contributor

For anyone reading this thread... I called Esri customer support and got hooked up with someone there. Unfortunately, both IDLE and Spyder refused to work while on the support call and shortly after my computer decided it needed to corrupt the Windows files. I had to then reinstall Windows 10 fresh on my machine. Long story short, on this completely fresh install (even though I had reinstalled ArcGIS Pro several times to no avail) my code works without a hitch.

I'm hoping nothing I do such as installing other software breaks it, but if it does I will report back so maybe we can track down what is causing this.

0 Kudos
ThomasBlankinship
New Contributor

The issue recurred so I cloned my hard drive and then methodically uninstalled programs until it worked again. After uninstalling Autodesk River and Flood Analysis Module 2018 and 2018.1 Update for Autodesk Civil 3D my scripts worked. To confirm, I cloned my hard drive again and removed these modules only and my scripts worked. I am unsure what is causing this issue, but evidently the people at Autodesk had some idea about it as they fixed the issue in the 2019.1 Update. See release notes for the update in the link below.

Autodesk® River and Flood Analysis Module 

0 Kudos