2

Working with 10.2.2, 64bit geoprocessing arcpy installation. Getting this error from arcpy.CalculateField_management() command.

From Spyder IDE in an ipython console, I get the error:

[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
 File "C:\Users\Nick\appdata\local\enthought\canopy\user\lib\site-packages\IPython\kernel\zmq\ipkernel.py", line 245, in dispatch_shell
 handler(stream, idents, msg)
 File "C:\Users\Nick\appdata\local\enthought\canopy\user\lib\site-packages\IPython\kernel\zmq\ipkernel.py", line 400, in execute_request
 reply_content.update(shell._showtraceback(etype, evalue, tb_list))
 File "C:\Users\Nick\appdata\local\enthought\canopy\user\lib\site-packages\IPython\kernel\zmq\zmqshell.py", line 501, in _showtraceback
 sys.stdout.flush()
AttributeError: 'geoprocessing sys.stdout object' object has no attribute 'flush'

It doesn't seem to have anything to do with the specifics of the command, and I can execute most other arcpy commands without problem.

Suggestions?

Here's the code I was running to get up to this (although I've tried this with different targets and different expressions -- it just seems to be the command, not the specifics):

ap.CalculateField_management(in_table = thiessens, field = 'primarySiteID', 
 expression = "!SITEID!",
 expression_type = 'PYTHON')

At this point I'm pretty sure it's an incompatibility with iPython that only appears in the context of some of the field-editing commands (since I use iPython all the time and usually without issue...)


Pretty sure it's iPython -- have the same issue with a different ipython install on a different computer, so I don't think it's Spyder or that specific installation.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 9, 2015 at 3:50
9
  • Can you show the lead up to what caused this, did you for instance call arcpy.CalculateField_management() with no parameters? Is ipython usually compatible with arcpy? It's not one that I've used before. Commented Mar 9, 2015 at 3:55
  • added. Seems to be about the command, not specific arguments. I've tried a few different CalculateField commands. Commented Mar 9, 2015 at 4:00
  • Does it raise any sort of error on command line or in python window on ArcCatalog? It could be that the geoprocessing.result object or exception raised might not conform to what ipython expects. Are you importing arcpy as ap? Try disabling the 64bit background geoprocessing, that is known to cause (nonspecific) problems. Commented Mar 9, 2015 at 4:05
  • Yes, sorry -- `import arcpy as ap'. And yes, runs fine in arcmap python window. But hard to write fancy loops in the python window! Commented Mar 9, 2015 at 4:12
  • I think it might be time to dump ipython. ArcGis has an inbuilt editor IDLE, I prefer PyWin wiki.python.org/moin/PythonWin - you can import arcpy on the interactive window and then use intelitext. Other reasonable options are Notepad++ and Textpad (not free) which come with syntax highlight. Commented Mar 9, 2015 at 4:34

1 Answer 1

2

Part of the problem is the way the CalculateField_management tool is coded. It almost certainly uses the Python command sys.stdout.flush(), which is misinterpreted by ArcGIS as a geoprocessing object.

I ran into this problem with code that I wrote with sys.stdout.flush(). The simple solution was to remove sys.stdout.flush() to avoid the conflicts, which is a patch ESRI could implement.

I don't know what in ArcGIS is causing it to be interpreted as a geoprocessing object. This seems to depend on how you run the code. I do not get an error when I run the code in a normal console in Spyder on a separate install of Python (Anaconda), but I do get the error when I run the code from an ArcGIS toolbox on the default Python installation.

FYI: sys is the system module in Python. sys.stdout.flush() tells Python to write any print statements immediately (printing is slow, so by default Python may wait to print). See more here: https://stackoverflow.com/questions/10019456/usage-of-sys-stdout-flush-method

answered Aug 17, 2016 at 21:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.