Select to view content in your preferred language

Can't use debugger in IDE, throws errors when there are none.

2488
8
01-23-2018 08:43 AM
MKF62
by
Frequent Contributor

EDIT: I moved my code to a different IDE and it works in debug there. It's a problem with PyCharm, anybody know how to fix it?

I have no idea why this is happening, it just started occurring today. My python script runs fine as long as I don't run it in debug mode... in debug mode I get all sorts of errors about datasets not existing or parameters being invalid for certain tools. When I take that chunk of code causing issues, put it in it's own script and run it, it runs just fine. All the datasets DO exist, they all DO have features, all the arcpy statements are written correctly, and for the life of me I cannot fix this. I NEED to be able to use debugger, this is getting ridiculous. 

I'm using PyCharm IDE, just updated to the most recent version. I haven't had this problem before with PyCharm, has anybody else? I'm wondering if it's something with the IDE. I haven't changed much of my code today at all, maybe a few lines. 

I think part of the problem is creating/using in_memory feature classes. To fix this, I attempted to hardcode some of the outputs to my directory instead of using in_memory but it just changed the error message in debug mode to something else, rather than fixing the issue.

This has been a long process of changing error messages and I couldn't describe them all to you if I tried, but one of them arose after trying to run the buffer tool:

qhPolys = arcpy.Select_analysis(svyPtFC, 'in_memory/qhPolys', select_query)
qh_buffer = arcpy.Buffer_analysis(qhPolys, 'in_memory/qh_buffer', '50 Meters')‍‍‍‍‍‍

The error message received here said that qhPolys didn't exist. I changed the in_memory/qhPolys to be hardcoded to my output directory. Still the same error occurs in debug ONLY. Again, I reiterate, the script works just fine if I let it run normally without debugging.

After a bunch of messing around trying to figure out the issue, I eventually just reset the above coded lines to in_memory and debug worked fine through those (for no reason whatsoever, apparently) until a few lines down. Line 5 below started to give me issues saying that "ERROR 000732: Input Features: Dataset # 1;# 2 does not exist or is not supported"

qhPolys = arcpy.Select_analysis(svyPtFC, 'in_memory/qhPolys', select_query)
qh_buffer = arcpy.Buffer_analysis(qhPolys, 'in_memory/qh_buffer', '50 Meters')      
cropFID = '"FID" = {0}'.format(cropPatch)
cropPoly = arcpy.Select_analysis(svyPtFC, 'in_memory/cropPoly', cropFID)
crop_intersect = arcpy.Intersect_analysis([[cropPoly, 1], [qh_buffer, 2]],
                                                        r'C:\Users\xxx\GIS_Testing\intersect2.shp')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I added these lines to determine that cropPoly and qh_buffer are, indeed, populated with features and shouldn't be giving any error messages. When I tested this with debugging on, it magically stepped through this without throwing the above error message like before (what the ****)

feature_count2 = arcpy.GetCount_management(cropPoly)
feature_count3 = arcpy.GetCount_management(qh_buffer)
if feature_count2 > 0 and feature_count3 >0:
        crop_intersect = arcpy.Intersect_analysis([[cropPoly, 1], [qh_buffer, 2]],
                                                        r'C:\Users\xxx\GIS_Testing\intersect2.shp')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

THEN on the next line, I got this error message: "Error 000735: Input Row: Value is required"

feature_count = arcpy.GetCount_management(crop_intersect)‍‍‍

crop_intersect has features. I went into ArcMap and checked the attribute table, there are records there to count. THERE IS NO REASON I SHOULD BE GETTING THIS ERROR MESSAGE.

I'm way beyond frustrated at this point. I have shut down and restarted my computer even to see if it was just a glitch. Why won't my script work in debug mode but it works just fine without it?

Tags (1)
0 Kudos
8 Replies
MKF62
by
Frequent Contributor

So I transferred this code to a different IDE called Wing. It works in debug there, so it's an issue with PyCharm. Leaving this question marked as "unanswered" because I wonder if anybody knows how to fix PyCharm. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you plan to use ArcGIS PRO you might want to invest some time in Spyder and Jupyter console and notebook which come with the Pro conda distribution. ( I have a few blog posts on Spyder etc)

0 Kudos
MKF62
by
Frequent Contributor

I probably will move to Pro eventually, but not yet. How do you install the 2.7 interpreter on Spyder? I went to Tools > Preferences > Python Interpreter and set it to C:/Python27/ArcGIS10.5/python.exe but when I try to run the code it says it can't find the arcpy module.

0 Kudos
DanPatterson_Retired
MVP Emeritus

When you are ready for Pro... not before.  

Pro manages everything... ArcMap doesn't

0 Kudos
QuinnBast
Occasional Contributor

I kno wthis is quite a bit old, but I just wanted to comment here and say that I am observing the same behavior with ArcGIS Pro using the pycharm debugger. My code is super simple, it will run without the debugger ,however, it will not run when the debugger is active.

with arcpy.da.SearchCursor(
    in_table=database_file,
    field_names="*") as search_cursor:

    for row in search_cursor:
        print(str(row))‍‍‍‍‍‍

Now that I've realized this problem, it is starting to make sense as to why some problems I have been running into seem ot solve themselves when the scripts run...

Edit:

ArcGIS Pro 2.1.2

PyCharm 2018.2 (Community Edition)
Build #PC-182.3684.100, built on July 24, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Can you provide some more information about database_file? Also, if you run the latest version of Pro does it work?

I ran your code using a file geodatabase in PyCharm and it works fine.

System:

ArcGIS Pro 2.2.1

PyCharm 2018.2.2 (Professional Edition)
Build #PY-182.4129.34, built on August 21, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

QuinnBast
Occasional Contributor

Unfortunately I am unable to upgrade Pro due to corporate security software regulations.
The database_file is a string which points to the location of an .sde file. The sde file is an oracle database connection. In the SearchCursor I also append a table name to the file as such:

database_file + r"/USER.FEATURECLASS/USER.POINTFEATURES"


After some further inspection I found that if I set a breakpoint before the for loop, the debugger will skip over the loop regardless of using "Step Over" or "Step Into". However, if I set a break point inside the for loop it will properly enter, execute, and debug within the loop.

Once the debugger skips the first loop, future loops can be entered and debugged fine. Additionally, while debugging, no print statements in the first loop are executed so during debugging the first loop is not entered at all while running without the debugger will perform the print statements in the first loop.

0 Kudos
MKF62
by
Frequent Contributor

I know it's not the ideal solution, but I've had a lot of success using Visual Studio as my main IDE. I got fed up with PyCharm and switched over - I don't miss PyCharm one bit.

0 Kudos