I recently began having issues using the debugger in Visual Studio Code. It has always worked in the past (and still does except with arcpy). Now every time I try to import arcpy I get a "name 'unicode' is not defined" error that is coming from _base.py. I am using python 3.9.16 64 bit interpreter and have the most current version of arcgis pro installed. I have tried to uninstall VS Code and ArcGIS Pro both and the same issue persists, but the second I comment out the import arcpy the debugger works fine (until it gets to something that needs the arcpy lib obviously). Any thoughts? I really like the VS Code IDE and would like to continue using it but am also open to similar easy to use options if anyone has any that might solve my issue.
Solved! Go to Solution.
You likely have 'Raised Exceptions' enabled as a breakpoint. Uncheck it and your script should run as expected.
The NameError is being raised because unicode is not defined, but it is handled by the except clause. @ShaunWalbridge mentioned, that try statement is likely unnecessary at this point. However, it isn't actually causing any problems with your script.
Did you do any specific configuration to add more verbose warnings or other configuration changes? I believe that VSCode + ArcPy is a common combination in use, and the `unicode` call, while failing, is expected to because it is wrapped in a try/except block which will raise on Python 3. These should ultimately be removed from the ArcPy code in the future, but I wouldn't expect a Python import to fail on them. You could check if only your code is set to debug, but also try making a dummy script with the same try / except lines as you're seeing raise, and see if that also fails.
Cheers, Shaun
Thank you for the reply. In the past I haven't had any issue with debugging. I haven't changed any configurations and have tested with a script I know works and in the past was able to debug. Currently I am trying to test with the simplest test script possible and I still get the same error. The code I am trying currently is (also note I have tried running just the top 3 statements and it also bombs and returns the unicode error):
import os
Right, unfortunately that script still imports ArcPy, so it doesn't help determine whether the problem affects all Python code or is specifically within ArcPy. Can you see if this script runs successfully?
try:
unicode
except:
print("In Python 3, all strings are unicode")
If that also fails, it lets us know that the issue is affecting all Python code. If it prints the output, then its something in the relationship with ArcPy specifically.
Cheers, Shaun
Shaun - Thanks again for the suggestions. Below is
OK, if that script doesn't print In Python 3, all strings are unicode then it indicates there is some broader issue with the debugging configuration of VSCode. I would double check the Python interpreter configuration, and perhaps try creating a separate clean profile to see if you can reproduce the error there as well and isolate any possible configuration changes. Unfortunately, if the basic Python configuration doesn't respect the normal exceptions model, there's not much we can do on the ArcPy tier to handle the problem.
Cheers, Shaun
You likely have 'Raised Exceptions' enabled as a breakpoint. Uncheck it and your script should run as expected.
The NameError is being raised because unicode is not defined, but it is handled by the except clause. @ShaunWalbridge mentioned, that try statement is likely unnecessary at this point. However, it isn't actually causing any problems with your script.
Thank you @NatKrase and @ShaunWalbridge.
I'm having the same problem. I unchecked the "Raised Exceptions" and "User Uncaught Exceptions" in the breakpoints section. So now I don't get an error at all...but the script still isn't running. The script, in its entirety is as follows. I get nothing at all. I AM able to log on to the server in a browser so I know ID and PW are correct and that the server is running.
==== code follows ==================
==== code end ==================
@Alex_Rodriguez, you said that is the script "in its entirety". The script you posted doesn't import arcpy, so it really may not be doing anything.
My apologies if I read too much into that statement.