Error setting workspace in arcpy.env

3552
5
10-12-2011 08:51 AM
SarahReed
New Contributor
Hello,

I am encountering errors with setting a workspace file path in some installations of ArcGIS 10. When I run the code in a Python editor, it runs fine. When I run the code in the Python window or as a script tool, it fails on 2 out of 4 machines I have tested, resulting in the error message 00732: the dataset doesn't exist or is not supported.

Here is the relevant section of code:

# Import system modules
import sys, os, string, arcpy

# Define workspace
arcpy.env.workspace = "c:/WorkSpace/Exercise3"

# Set overwrite option
arcpy.env.overwriteOutput - True

# Define the input datasets
cities = "Larimer_Cities.shp"
county = "Larimer_County.shp"

...

The script fails when it calls for the first input dataset, which it does not find. I have tried various ways of representing the workspace filepath (/, \\, r"..), and the only successful workaround I have found is to specify the full filepath for all input and output datasets. Since this only happens on some of the ArcGIS installations I have tested, it leads me to believe that somehow the environment setting for workspace is being overridden. Any ideas?

Thanks,
Sarah
Tags (2)
0 Kudos
5 Replies
AndrewChapkowski
Esri Regular Contributor
I noticed you have this
arcpy.env.overwriteOutput - True

but it should be
arcpy.env.overwriteOutput = True


In addition, you can try doing the following:
cities = str(arcpy.env.workspace) + os.sep + "Larimer_Cities.shp"


Does the data exist at the workspace path specified?  If I do for example this:
import arcpy
arcpy.env.workspace = r"pathto\scratch.gdb"
desc = arcpy.Describe("FeatureClassName")
print desc.name

I get the feature class's name.

You can also test your code by using the arcpy.Exists():
arcpy.env.workspace = "mypath"
cities = "Larimer_Cities.shp"
print arcpy.Exists(cities)
0 Kudos
SarahReed
New Contributor
Apologies for that first mistake; it was a typo.

The data does exist within the workspace path specified. When running the script from the Python window, I am able to confirm that the workspace path is set correctly and that the feature class exists, but when I reach the first analysis that calls for the data (in this case, a buffer analysis), I stlll get the error message stating that the data does not exist.

The alternate syntax you suggested (specifically, converting the workspace path to a string) does work, but I am still confused about why the syntax given by ESRI does not work in some cases.

Is there some way that my environment settings are being overridden, even during the execution of a script?
0 Kudos
MathewCoyle
Frequent Contributor
Is this being done in the Python window in ArcMap? Have you tried running it as a stand alone script?
0 Kudos
SarahReed
New Contributor
Yes, running it as a stand-alone script (from PythonWin or IDLE) works fine with the standard syntax for setting a workspace. I encounter the error only when running the script from the Python window or as a script tool in ArcToolbox.
0 Kudos
MathewCoyle
Frequent Contributor
Open a fresh instance of ArcMap, go to Geoprocessing > Environments remember what it says is your current workspace. Then go to the Python window and enter
print arcpy.env.workspace
If they don't match there is a problem somewhere deeper than simple code may be able to fix. I've seen some wonky things happen with errant registry edits moving default workspaces around.
0 Kudos