Select to view content in your preferred language

copy features error in python and not modelbuilder

5849
6
Jump to solution
09-24-2013 04:31 PM
AmyKlug
Frequent Contributor
 import arcpy from arcpy import env arcpy.env.overwriteOutput = True arcpy.CopyFeatures_management("U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line", "U:\TEST_2.gdb\lines\other_line")   


Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 2227, in CopyFeatures     raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line does not exist or is not supported WARNING 000725: Output Feature Class: Dataset U:\TEST_2.gdb\lines\other_line already exists. Failed to execute (CopyFeatures). 


I have tried taking out the underscores. Geoprocessing options are set to overwrite as well. The biggest issue is the line that does not exist/not supported

Any ideas?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
When using Python, a single backslash is known as an escape" rel="nofollow" target="_blank">http://docs.python.org/release/2.5.2/ref/strings.html]escape character. Therefore, to use a backslash you must use a double backslash or use the raw string method. So for your paths you can supply them one of 3 ways:

 # double backslash line = "U:\\GIS_Data\\Geodatabase\\TEST_2.mdb\\lines\\other_line"  # raw string (easiest method) line = r"U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line"  # forward slash line = "U:/GIS_Data/Geodatabase/TEST_2.mdb/lines/other_line"


The second option is the easiest in my opinion. Try changing your code to:

import arcpy arcpy.env.overwriteOutput = True  # variables original = r"U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line" copy = r"U:\TEST_2.gdb\lines\other_line"  # explicitly delete output if it exists if arcpy.Exists(copy):    arcpy.Delete_management(copy)  # copy features tool arcpy.CopyFeatures_management(original, copy)   


Here is a quick example to show you how some escape characters work. The '\n' is the new line character, and the '\t' is a tab.

>>> test = 'C:\Data\new_folder\tables\Schools.dbf' >>> print test C:\Data ew_folder ables\Schools.dbf >>> test = r'C:\Data\new_folder\tables\Schools.dbf' >>> print test C:\Data\new_folder\tables\Schools.dbf >>> 


Also, I just took another look at your error messages...Did you install the 64" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/index.html#//002100... bit background processing? If so, your Python may be defaulting to the 64 bit Python version, which does not support Personal geodatabases. Otherwise, you could try explicitly deleting the output if it exists.

View solution in original post

0 Kudos
6 Replies
by Anonymous User
Not applicable
When using Python, a single backslash is known as an escape" rel="nofollow" target="_blank">http://docs.python.org/release/2.5.2/ref/strings.html]escape character. Therefore, to use a backslash you must use a double backslash or use the raw string method. So for your paths you can supply them one of 3 ways:

 # double backslash line = "U:\\GIS_Data\\Geodatabase\\TEST_2.mdb\\lines\\other_line"  # raw string (easiest method) line = r"U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line"  # forward slash line = "U:/GIS_Data/Geodatabase/TEST_2.mdb/lines/other_line"


The second option is the easiest in my opinion. Try changing your code to:

import arcpy arcpy.env.overwriteOutput = True  # variables original = r"U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line" copy = r"U:\TEST_2.gdb\lines\other_line"  # explicitly delete output if it exists if arcpy.Exists(copy):    arcpy.Delete_management(copy)  # copy features tool arcpy.CopyFeatures_management(original, copy)   


Here is a quick example to show you how some escape characters work. The '\n' is the new line character, and the '\t' is a tab.

>>> test = 'C:\Data\new_folder\tables\Schools.dbf' >>> print test C:\Data ew_folder ables\Schools.dbf >>> test = r'C:\Data\new_folder\tables\Schools.dbf' >>> print test C:\Data\new_folder\tables\Schools.dbf >>> 


Also, I just took another look at your error messages...Did you install the 64" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/index.html#//002100... bit background processing? If so, your Python may be defaulting to the 64 bit Python version, which does not support Personal geodatabases. Otherwise, you could try explicitly deleting the output if it exists.
0 Kudos
curtvprice
MVP Alum
0 Kudos
AmyKlug
Frequent Contributor
When using Python, a single backslash is known as an escape character. Therefore, to use a backslash you must use a double backslash or use the raw string method. So for your paths you can supply them one of 3 ways: 


# double backslash
line = "U:\\GIS_Data\\Geodatabase\\TEST_2.mdb\\lines\\other_line"

# raw string (easiest method)
line = r"U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line"

# forward slash
line = "U:/GIS_Data/Geodatabase/TEST_2.mdb/lines/other_line"


The second option is the easiest in my opinion. Try changing your code to: 

import arcpy
arcpy.env.overwriteOutput = True

# variables
original = r"U:\GIS_Data\Geodatabase\TEST_2.mdb\lines\other_line"
copy = r"U:\TEST_2.gdb\lines\other_line"

# explicitly delete output if it exists
if arcpy.Exists(copy):
   arcpy.Delete_management(copy)

# copy features tool
arcpy.CopyFeatures_management(original, copy)
  


Here is a quick example to show you how some escape characters work. The '\n' is the new line character, and the '\t' is a tab.  

>>> test = 'C:\Data\new_folder\tables\Schools.dbf'
>>> print test
C:\Data
ew_folder ables\Schools.dbf
>>> test = r'C:\Data\new_folder\tables\Schools.dbf'
>>> print test
C:\Data\new_folder\tables\Schools.dbf
>>> 


Also, I just took another look at your error messages...Did you install the 64 bit background processing? If so, your Python may be defaulting to the 64 bit Python version, which does not support Personal geodatabases. Otherwise, you could try   explicitly deleting the output if it exists.


Yeah, I tried all that yesterday and again today after I read this just to be sure and same result. scratching head

I also exported the model as python code. the model runs fine, the code doesn't!

I copied the .gdb into the folder with the .mdb and did a copy in the python window and it worked (copied from .gdb to .gdb). something is wrong with the mdb when used with python. But it works as a model, I can also copy it manually

I also made sure the files were not read-only

Ideas? I am trying to run this as a scheduled task or else I would just use the model.

EDIT: Didn't read the bottom of you post.......I am running 10.1 with SP1 and did switch to the 64 bit processing. It's always something 🙂
0 Kudos
MichaelVolz
Esteemed Contributor
What kind of machine are you running the scheduled task from (e.g. Windows Server 2008, Windows XP, Windows 7)?
0 Kudos
by Anonymous User
Not applicable
EDIT: Didn't read the bottom of you post.......I am running 10.1 with SP1 and did switch to the 64 bit processing. It's always something

Ok, since you have the 64 bit python you need to force it to run 32 bit python.  You can set up a simple batch file like this to run 32 bit:

start C:\Python27\ArcGIS10.1\python.exe  G:\PROJECTS\Cedar\GeneralScripts\PyLibrary\FormattedExcel.py


I usually create files like this in notepad and save it with a .bat file extension


note the path for python.exe:  C:\Python27\ArcGIS10.1\python.exe

The path for the 64 bit is:  C:\Python27\ArcGISx6410.2\python.exe

64 bit has the "x64" in the folder name.  Make sure you use 32 bit python when working with personal GDB's, coverages, excel files, etc.

You can always see what version you are running by typing this in the python shell:

import sys

print sys.version


For my 64 bit, it prints:

2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]


For my 32 bit it prints:

2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]
0 Kudos
AmyKlug
Frequent Contributor
It didn't work the first few times but seems to be working now (after I changed the output folder once again write/read) with the batch file set to 32, great tip.

When I checked my version it says I'm using 32 bit (2.7.2). go figure?

EDIT: It still doesn't run in the python window

EDIT2: I went to geoprocessing options and disabled background processing and now it works in python window too.
0 Kudos