Code working in ArcGIS Pro Python Window but not in Spyder

6169
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
ThomasBlankinship
New Contributor

I did, I guess I'm just a bit confused. I don't need python 3.7, Anaconda 3.7 is just the installer they have on the Anaconda website. I might be dense, but it shouldn't matter because I am using a separate environment for my arcgispro-py3-clone right?

Regardless, I am going to try to delete the clone, uninstall the Anaconda Navigator I got from their website installer, and install the packages directly into "C:\Program Files\ArcGIS\Pro\bin\Python\arcgispro-py3" folder using conda from "proenv.bat" and see if that works.

0 Kudos
DanPatterson_Retired
MVP Emeritus

uninstall everything,

Install arcgis pro

If you have no other packages other than spyder to install, you can either install it in the default or a cloned environment, assuming you have full administrative rights to your machine.

/blogs/dan_patterson/2018/12/13/spyder 

/blogs/dan_patterson/2019/06/28/arcgis-pro-24-installation-package-updates-and-installs 

/blogs/dan_patterson/2018/12/28/clone 

/blogs/dan_patterson/2017/07/01/arcgis-pro-2-creating-desktop-shortcuts 

And I have more on my blog

0 Kudos
ThomasBlankinship
New Contributor

Ok, working on that now. Uninstalled ArcGIS Pro and Anaconda and all related folders, files, registry keys, etc. that were left over after installation. Just installed ArcGIS Pro 2.3 and its three patches in "C:/ArcGISPro" shortening the path like you suggested. I have full control over my computer so am not making a clone.

Now updating numpy from proenv.bat (located at C:\ArcGISPro\bin\Python\Scripts) and learning about sphinx and will downgrade if I decide I want to. Next I will install Spyder. If I install anaconda-navigator after that is there anything else I have to do to get that to work properly?

Thanks again for your assistance.

0 Kudos
DanPatterson_Retired
MVP Emeritus

leave out Anaconda Navigator for now.  It is a longer story and requires a patch that I haven't tested on Pro 2.4

0 Kudos
ThomasBlankinship
New Contributor

The patch mentioned in https://community.esri.com/blogs/dan_patterson/2018/12/28/clone ?

I am using 2.3.3 which is what you used for that I believe.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Thomas... get it working first before you try the patch

0 Kudos
ThomasBlankinship
New Contributor

Fair enough. My problem still is not solved though, works in Python Window in ArcGIS Pro but not in Spyder. What the heck?

0 Kudos
TonyDaSilva1
Occasional Contributor

I am having the same problem but I am not using Spyer. I am simply editing my code in Visual Studio Code and running it using the built in ArcGIS Python Interpreter. At first it was teh clip tool but now simple trying to add a field does not work anymore.

"pythonPath": "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\python.exe"

>>> import arcpy
>>> fc = r"E:\Data\Parks.gdb\rsBox"
>>> arcpy.AddField_management(fc, "Update", "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
>>>

Link to my question:

https://community.esri.com/message/867419-runtimeerror-object-error-in-executing-tool

0 Kudos
ThomasBlankinship
New Contributor

Any ideas? This has thoroughly stumped me. It won't work with the IDE installed with ArcGIS Pro either.

0 Kudos
DanPatterson_Retired
MVP Emeritus

As a lark... change your field name to Update_ or something else.

I tend to avoid any keywords associated with anything.  For example

Reserved Keywords (Transact-SQL) - SQL Server | Microsoft Docs 

I couldn't find an equivalent list in the help files... would be nice, but I suspect that it may be database dependent

0 Kudos