1

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.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Nov 4, 2019 at 21:36
4
  • Have you tried using IDLE instead of command line? I think IDLE comes with the Arc install of Python 2.7, launching IDLE should link to the right Python installation Commented Nov 4, 2019 at 21:39
  • I'm usingAtom to write the scripts - I dont think you can execute entire scripts within IDLE? Thanks. Commented Nov 4, 2019 at 21:59
  • does this help? youtube.com/watch?v=q0RSjeUaLcw see about 2 mins in Commented Nov 4, 2019 at 22:14
  • @AlexS1 IDLE comes with it's own set of problems, I find PyWin much better, I would recommend the python window in ArcCatalog or ArcMap (you can even copy/paste multiple lines) to run test scripts. The problem here is that there are multiple installs of python but only one will work with arcpy. Have a read through gis.stackexchange.com/questions/268241/… and see if there's some helpful advice there. Commented Nov 5, 2019 at 2:07

1 Answer 1

3

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>>>

answered Nov 4, 2019 at 23:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.