26

I'm trying to take the next step in programming ArcGIS with Python and see if its actually possible to run my script/code without having to load ArcMap and paste them into the Python window. I imagine I would do this view some sort of IDE specific to Python that loads something from ArcGIS.

How would I got about doing this?


Update: Summary of the solution

I went the Eclipse + PyDev route. Here are my notes on installing everything and getting it working:

Download Eclipse

This is slightly confusing given all the different flavors that are available (Java, Java EE, C/C++, etc.). I went with C/C++ since that's what familiar to me. It doesn't really matter since PyDev gets installed after this step. Pick what you want.

Install PyDev

PyDev will be installed via Eclipse. The instructions linked worked perfectly.

Configure PyDev

The above question gives a screenshot of a Windows configuration, while this link from an ESRI blog has more info for Unix systems although it is from 2008.

Ran a test script

Fired up a script I had been working on and it worked. There seems to be some differences in executing code in this way in how to access shapefiles and the workspace, etc, more explicitness is required. More to learn here.

5
  • I confess this seems almost more of a Python question and also betrays my ignorance of the Python environment, but hopefully the answer is of use to others who are new to ArcGis + Python! Commented Jan 5, 2012 at 23:08
  • I think using IDLE would've been easier. PyDev is a bit of an overkill in this situation I think. You might also want to build some models in Model Builder and export them as .py files. That way you'd have a feel for the Python code.
    – R.K.
    Commented Jan 8, 2012 at 13:45
  • This is simply repeating what I have said! It is the best though isn't it. The key with using it this way, is that you're able to create Objects and classes which some of the other ways doesn't support. It allows you to really concentrate on building cracking code, deployable on the server. Good luck!
    – Hairy
    Commented Jan 10, 2012 at 8:55
  • 2
    Mindless, only one reply here mentions the Eclipse + PyDev solution. Is there a reason you did not vote it up?
    – whuber
    Commented Jan 11, 2012 at 13:37
  • None. I accepted the Eclipse suggestion since that's the way I went and preferred. I only answered my own question to document the setup process. Any reason my answer should be edited into the question? Perhaps this should be a CW? Commented Jan 11, 2012 at 17:25

5 Answers 5

15

I have just started to get to grips with Python and arcpy and I found PyScripter really useful. Its a full-blown Python IDE

2
  • 2
    Best IDE I've used to date is PyScripter and it's free!
    – Hornbydd
    Commented Jan 6, 2012 at 15:56
  • 2
    PyScripter is really great. Excellent code completion, syntax highlighting, search & replace, tabs for showing multiple PY scripts. Much more useful than IDLE in my opinion. Commented Jan 6, 2012 at 19:39
15

If I understand the question, you want run your scripts standalone, outside of the ArcMap session. Totally do-able. Save your code into a Python file (.py). As far as editing, you can use IDLE or any text editor (even Notepad) for that matter. Sometimes when you are starting out, it's easier to use a text editor so you can focus on learning the code, not the IDE. Make sure you have your PATH environmental variables setup properly, so they include your Python install directory, something like:

C:\Python26\ArcGIS10.0\Lib\site-packages\;C:\Python26\ArcGIS10.0;C:\Python26\ArcGIS10.0\Scripts

Then it's simply a matter of opening up a command prompt (Start > Run > type 'cmd' [without the quotes]) and typing:

python c:\path\to\python\script.py

Now, this assumes you have all of your data paths hardcoded in the script.

That's the basics. There of course is way more, like using input parameters.

1
  • 3
    just a comment regarding IDLE or a standard text editor. I personally find PythonWin a much easier way to work since it has better debugging capabilities - crucial while learning. See instructions on installing PythonWin with ArcGIS 10. You do need to ensure you install the version of PythonWin from the ArcGIS DVD, or it can break the Python installation. Commented Jan 5, 2012 at 23:46
11

The best way I have found to use Python, is using Eclipse with PyDev. It's a good IDE for developing with and allows for inline debugging, not commend line debugging, and it has allwoed me to build very professional back end Data Management applications on a large scale.

IDLE is only ever that good for testing scriplets, in my opinion, and isn't good for designing complex object based solutions.

It's also incredibly easy to set up.

2
  • Is there much involved with getting Eclipse + PyDev to work w/ ArcGIS functionality? Other answers seem to indicate some peculiarities with using the non-Arc installed Python? Commented Jan 6, 2012 at 14:38
  • None at all, simply ensure you have arcgis desktop installed, and set up Eclipse to work with PyDev and you're away. It took 5 mins to set it up and then all you havw to do is reference arcpy in your script. Seriouly, I have not seen an easier, better way to do it.
    – Hairy
    Commented Jan 6, 2012 at 15:46
6

When ArcGIS installs it installs its own version of python(ie you don't need to import the dependencies).. be sure to use this one..

I use python CLI as a calculator as well as running saved scripts.

Python as a calculator is great as you can define variables.. I got this tip from the python tutorials http://docs.python.org/

I have a shortcut to the CLI via command prompt on my task bar %windir%\system32\cmd.exe /k "C:\Python26\ArcGIS10.0\python.exe"

I used windows scheduled tasks to do some maintenance via scripts that i exported out of model builder and then hacked in some changes to python built-ins such as applying dates to filenames for backups.

5

I believe an IDE for python comes with the ArcGIS-10 installation. It is called IDLE, and is a simple but effective tool for interfacing with ArcPy without opening an instance of ArcMap itself. You should be able to find it under the "Python 2.6" directory of your ArcGIS installation on the start menu. Just be sure to import arcpy before performing anything specific to the package! Any script example you see in the ArcPy reference for standalone scripts will work in IDLE's interface.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.