3

I'm learning ArcPy, when I run this code from Python on ArcMap it works. But it does not work from the separate Python shell.

import arcpy
from arcpy import env
import os
output_dir = "C:/Data"
env.workspace = os.path.join(output_dir, "Output.gdb")
env.overwriteOutput = True 
output_features = "name"
origins = "C:\Users\username\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\Connection to sde.sde\SDE.tablename" 
arcpy.management.CopyFeatures(origins, output_features)

I'm getting arcgisscripting.ExecuteError: ERROR 000210: Cannot create output 'name' Failed to execute (CopyFeatures).

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Jan 5, 2018 at 9:06
1
  • Please edit the question in response to requests for clarification or answers that don't solve your issue. You have a glaring naming bug (failure to use double-backslash or the raw formatting prefix (r"C:\foo") but it seems there are multiple issues, so you should update your code. Commented Jan 5, 2018 at 10:51

2 Answers 2

3

You haven't defined a workspace for your output, just a basename. If you run your script in ArcGIS, arcpy will use the default workspace defined at the application level. But this won't work outside ArcGIS. Either

  • use arcpy.env.workspace (e.g. arcpy.env.workspace = r"C:\Data\gdb.gdb) in the beginning of your script to set the workspace,
  • or set the full path to your output (e.g. output_features = r"C:\Data\gdb.gdb\name")

Note that the workspace (folder or gdb) must exist, it won't be created by Copy Features.

answered Jan 5, 2018 at 9:14
2
  • I added workspace to the code, still having the problem. Commented Jan 5, 2018 at 9:28
  • Are you sure the workspace exists? Commented Jan 5, 2018 at 9:29
0

You need to deal with the backslash which has special meaning to Python. I recommend using an r to treat it as a raw string.

origins = "C:\Users\username\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\Connection to sde.sde\SDE.tablename" 

should be:

origins = r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\Connection to sde.sde\SDE.tablename"
answered Jan 5, 2018 at 11:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.