Pyscripter

4089
1
02-08-2015 09:28 AM
PROBERT68
Frequent Contributor

I have a question about Pyscripter in which I am trying to understand.

Suppose if I set up a script within Pycripter and hit the run button to check for any errors.  You know if you copy the script from somewhere and paste it in Pyscripter and run it and sometimes Pyscripter does not understand but if you save it and load it in Python Window it would run fine.

Why are they both different ?

Here is the example:

Traceback (most recent call last):

  File "C:\workspace\GeoTIFF.py", line 12, in <module>

    mxd = arcpy.mapping.MapDocument("CURRENT")

NameError: name 'arcpy' is not defined

I understand that the error is because Pyscripter does not understand CURRENT because it is the way that Python window understands it.

Message was edited by: Robert Pollock add the e after past = paste

0 Kudos
1 Reply
DarrenWiens2
MVP Honored Contributor

It matters whether or not you run scripts within an ArcMap session, and within that session whether the script is run as a tool or from the Python window.

Your error is actually due to not importing the arcpy library. It is auto-loaded in ArcMap, but not standalone PyScripter. Make ' import arcpy ' (no quotes) the first line in a standalone arcpy script.

You are correct, though, that the ' CURRENT ' mxd will not be available standalone; reference it by file path.