arcpy.env.overwriteOutput = True fails

11186
2
Jump to solution
05-22-2014 11:01 AM
TychoGranville
Occasional Contributor II
Hi All,

Probably a newbie question...

I created a table-to-table routine in Model Builder which works as it should. The output table goes to a GeoDB, overwriting any same named table that is already there. I exported the model to Python and now I get the error 000258: Already Exists. I added
arcpy.env.overwriteOutput = True

to the script and it still fails. I tried adding the command
if os.path.exists

but it also fails (presumably since the table is inside the GeoDB?)

What did I miss?

Thanks,

Tycho
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
You're probably running into a file locking issue. That is, the table you are trying to replace is already locked by another process (probably a table view in memory), so you cannot delete it.  That app that has the lock may be your ArcMap session, another application (say ArcCatalog or Excel), or if you are using 10.1SP1 or later and ran background GP, the background GP session.

If you close ArcMap (and any other apps that may have the table open), and restart ArcMap, the lock should be released. If you are running your Python script from IDLE, that's another process so you will need to close Arcmap to release the lock so you can delete the output table.

Generally Python code exported to ModelBuilder is not very solid and requires some editing. But I think  your issue is about the table being open in ArcMap.

Hi All,

Probably a newbie question...

I created a table-to-table routine in Model Builder which works as it should. The output table goes to a GeoDB, overwriting any same named table that is already there. I exported the model to Python and now I get the error 000258: Already Exists. I added
arcpy.env.overwriteOutput = True

to the script and it still fails. I tried adding the command
if os.path.exists

but it also fails (presumably since the table is inside the GeoDB?)

What did I miss?

Thanks,

Tycho

View solution in original post

2 Replies
curtvprice
MVP Esteemed Contributor
You're probably running into a file locking issue. That is, the table you are trying to replace is already locked by another process (probably a table view in memory), so you cannot delete it.  That app that has the lock may be your ArcMap session, another application (say ArcCatalog or Excel), or if you are using 10.1SP1 or later and ran background GP, the background GP session.

If you close ArcMap (and any other apps that may have the table open), and restart ArcMap, the lock should be released. If you are running your Python script from IDLE, that's another process so you will need to close Arcmap to release the lock so you can delete the output table.

Generally Python code exported to ModelBuilder is not very solid and requires some editing. But I think  your issue is about the table being open in ArcMap.

Hi All,

Probably a newbie question...

I created a table-to-table routine in Model Builder which works as it should. The output table goes to a GeoDB, overwriting any same named table that is already there. I exported the model to Python and now I get the error 000258: Already Exists. I added
arcpy.env.overwriteOutput = True

to the script and it still fails. I tried adding the command
if os.path.exists

but it also fails (presumably since the table is inside the GeoDB?)

What did I miss?

Thanks,

Tycho
TychoGranville
Occasional Contributor II
Yep, the lock was the problem. Thanks for the help!

Tycho
0 Kudos