I am having trouble with how I am supposed to use both ArcPy and ArcGIS API for Python. ArcPy is only in Python 2 and ArcGIS API for Python is in ArcGIS Pro and is Python 3. I don't know how to set my paths in VS Code or Atom to be able to use both.
2No, your assertion is incorrect. ArcPy exists in both Python 2 and 3 (32-/64-bit Desktop and 64-bit Pro, respectively). API for Python is only for Python 3, and has a different purpose than ArcPy.– VinceJun 20, 2018 at 20:06
1Perhaps review gis.stackexchange.com/questions/248545 - maybe it is only ArcPy or the ArcGIS API for Python that you need to use. If so, it could simplify your Python setup.– PolyGeo ♦Jun 21, 2018 at 0:10
You can only run a Python script against one version of the Python debugger at a time (2.7, 3.4, etc).
If you have ArcMap, which runs against Python 2.x and the Python API (I'd assume you've installed Python 3.x and required dependencies), then you can't write a single script that calls
import arcpy import argis
In theory you might be able to write a script that sub-processes out to Python 3.x from the 2.7 one. As was pointed out in the comments, the ArcGIS Python API only runs against Python 3.x
Alternatively (actually, hopefully this is your case as this is easiest), if you're using ArcGIS Pro, which lays down Python 3.x and is handled via Conda, you can write one script that calls both
arcgis. Assuming you've loaded the Python API into the ArcGIS Pro (Conda managed) Python. In this case, you can call Python directly from
"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" However you should read this help topic as it goes into more detail about running Python.
Thanks for the response. When I set my python environment to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe in VS Code and run import arcgis and import arcpy I get the error ModuleNotFoundError: No module named 'arcpy' Jun 22, 2018 at 12:05
Which version of ArcGIS Pro do you have installed?– KHibmaJun 22, 2018 at 12:11
I have ArcGIS Pro 2.1.3 Jun 22, 2018 at 12:21
From the help link above in the
From a command promptsection, can you follow the instructions for trying Python from command prompt - once in there, try to
import arcpyand see if that gets your anywhere. Rule out a larger issue.– KHibmaJun 22, 2018 at 12:27
No errors when I do that. Jun 22, 2018 at 12:44