On some recent projects, I have been using ArcPy to script out some ArcGIS Pro feature automation. ArcPy ships as a package available via ArcGIS Pro’s Python package manager (which is essentially a GUI on top of Conda), and can be imported to any Python script. ArcGIS Pro’s package manager allows you to clone environments, and add/remove various packages; all the packages from Conda are available for install here:
I admittedly put most of the Python environment management on auto-pilot; I didn’t often need to use many packages that weren’t already installed by default and everything was just working. That was until a recent ArcGIS Pro version upgrade from 3.0.3 to 3.1.0. After updating ArcGIS Pro at the end of the day, I began the next working on a project where I needed to leverage a few functions found in ArcPy. Importing the library to my script did not throw any linting errors or warnings in VS Code; and I was able to write the code I needed. When it came time to test and debug, I was met with an error I had not seen before: “ImportError: version mis-match.”
I had not encountered this before when working with ArcPy, so after some quick googling and brainstorming, I remembered that I had set the location of the Python interpreter in VS Code to one of my cloned ArcGIS Pro/Conda environments. I realized there was likely a connection between the recent ArcGIS Pro upgrade and the version mismatch error message in the
ImportError exception that was being thrown when executing a script which attempts to import ArcPy.
From here I was able to select the environment I had set in VS Code and run the upgrade process:
However, this did not resolve the issue. From here, I cloned a new Python environment from the current default environment
After this completed successfully, I updated the Python interpreter path in VS Code (Settings > Extensions > Python > Default Interpreter Path), and then I was able to run my scripts without the
import arcpy statement throwing any exception; all the arcpy classes and functions work as expected. For more information on configuring your VS Code dev environment with ArcPy, see my previous post: Configuring VS Code for ArcPy/ArcGIS Pro development