How to debug arcpy code in visual studio 2019

269
3
05-13-2021 02:41 PM
ManishShrivastav
New Contributor III
# This script clips all feature classes in a file geodatabase

import arcpy

# Create path variables
sourceWorkspace = r"C:\Users\Lesson2Practice\USA.gdb"
targetWorkspace = r"C:\Users\Lesson2Practice\Iowa.gdb"
clipfeature = r"C:\Users\Lesson2Practice\Iowa.gdb\Iowa"

# Get a list of all feature classes in the USA geodatabase
arcpy.env.workspace = sourceWorkspace
featureClassList = arcpy.ListFeatureClasses()

try:
    # Loop through all USA faeture classes
    for featureClass in featureClassList:
        
        # Construct the output path
        outClipFeatureClass = f'{targetWorkspace}\Iowa{featureClass}'

        # Perform Clip
        arcpy.Clip_analysis(featureClass,clipfeature,outClipFeatureClass)
        arcpy.AddMessage(f'Wrote clipped file {outClipFeatureClass}.')
        print(f"Wrote clipped file {outClipFeatureClass}.")
except:
    # Report if there was an error
    arcpy.AddError("Could not clip feature classes")
    print("Could not clip feature classses")
    print(arcpy.GetMessages())

I have created a python script file that I am debugging it using visual studio 2019, But as soon as I try to debug, it gives me and Exception on another file (time.py - not sure where it came from as this time.py is not in my project or folder) stating "name 'm' is not defined" (I am attaching a video of the exception). Any help is appreciated.

 

Thanks

0 Kudos
3 Replies
GintautasKmieliauskas
Regular Contributor

Hi,

Have you solved issue with "name 'm' is not defined"?

I have the same situation as you

0 Kudos
ManishShrivastav
New Contributor III

I am still waiting for it.

0 Kudos
ChenChen4
New Contributor

I have the same issue. It looks like when I import arcpy in Visual Studio, it loads 'arcpy.time', and it doesn't matter if I use any datetime functions in my code but the debug detects the name error.

I opened the time.py file and in line 267, there is a variable m

try:
del m
except NameError:
pass

I cannot modify this time.py file since it's part of arcpy package. Don't know how to solve this problem.

0 Kudos