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.Vince– Vince2018-06-20 20:06:27 +00:00Commented Jun 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– PolyGeo ♦2018-06-21 00:10:54 +00:00Commented Jun 21, 2018 at 0:10
1 Answer
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 arcpy and 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'Chris– Chris2018-06-22 12:05:13 +00:00Commented Jun 22, 2018 at 12:05
-
Which version of ArcGIS Pro do you have installed?KHibma– KHibma2018-06-22 12:11:17 +00:00Commented Jun 22, 2018 at 12:11
-
-
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 toimport arcpyand see if that gets your anywhere. Rule out a larger issue.KHibma– KHibma2018-06-22 12:27:42 +00:00Commented Jun 22, 2018 at 12:27 -