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
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.


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.

  • 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. – Michael Stimson Mar 9 '15 at 3:55
  • added. Seems to be about the command, not specific arguments. I've tried a few different CalculateField commands. – nick_eu Mar 9 '15 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. – Michael Stimson Mar 9 '15 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! – nick_eu Mar 9 '15 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. – Michael Stimson Mar 9 '15 at 4:34

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.