ArcPy – Python Setup to Run ArcPy Scripts

arcpypowershellpython

I am trying to set up Python so that I can execute ArcPy scripts outside of ArcMap. I'm new to Python, however I have previously been able to execute Pythons scripts from the cmd prompt (PowerShell), however I can't execute any ArcPy related scripts (maybe I'm misunderstanding).

First thing is that when I type "python" in the cmd, I am getting a different version to the one ArcMap 10.3 is using, which is 2.7.

enter image description here

I have set the path in Windows Environment Variable –

enter image description here

I'm using a textbook and seemed to have followed the instructions, so i'm not sure where I've gone wrong.

Best Answer

You can execute your scripts by calling the python installation that comes with ArcGIS. In command prompt/powershell type (replace 'my_script.py' with your python script:

c:\python27\ArcGIS10.7\python.exe my_script.py

Check your path as it might be slightly different.

This will use the correct python version (2.7) and all the modules from ESRI will be available to import (arcpy is one of them).

If you just want to run python for testing in the terminal, open cmd/powershell and type:

c:\python27\ArcGIS10.7\python.exe

Which will open the python prompt >>>

Related Question