I am having some trouble running arcpy in VS Code. When I run my simple test scrtipt:

import arcpy

in_shp = r'S:\CVT\ChesterfieldTwp\Data\GIS\Layers\Utilities\SanitarySewer.shp'

for field in arcpy.ListFields(in_shp):

VS Code throws an error:

Exception has occurred: GeneratorExit
File "C:\Users\adoezema\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 44, in <genexpr>
  if not any(e in sys.version for e in ("Continuum", "conda-forge", "Anaconda")):
File "C:\Users\adoezema\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 44, in <module>
  if not any(e in sys.version for e in ("Continuum", "conda-forge", "Anaconda")):
File "C:\Users\adoezema\OneDrive - OHM Advisors\ArcTools, Models, and Scripts\Lynda Courses\Scratch.py", line 1, in <module>
import arcpy
 File "C:\Users\adoezema\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\adoezema\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\adoezema\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\Lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)

enter image description here

How do I fix this issue?

  • 2
    Could you please confirm that you can run that code in the ArcGIS Python terminal? Also, are you able to import arcpy in your above IDE? – Aaron May 11 '19 at 2:46
  • I can run the above code in ArcPro, ArcMap, and PyCharm. – adoezema May 13 '19 at 12:02
  • Cross-posted as stackoverflow.com/q/56082919/820534 – PolyGeo May 14 '19 at 12:00

Completely uninstalled and reinstalled vs code. This seemed to fix the issue.

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