Select to view content in your preferred language

arcpy.ImportToolbox('..Data Management Tools.tbx') fails with SP4

2090
2
Jump to solution
05-02-2012 09:00 AM
StevenHaslemore
Regular Contributor
Hi folks,

this problem started with install of SP4, I'd rather try and fix it than uninstall everything to try and get off SP4.

I've tried reinstalling SP4

import arcpy
>>> arcpy.ImportToolbox(r"C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 94, in ImportToolbox
return import_toolbox(input_file, module_name)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\toolbox_code.py", line 411, in import_toolbox
mymodule = generate_toolbox_module(toolbox, None, False, False, False, module_name)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\toolbox_code.py", line 389, in generate_toolbox_module
mycode = compile(code.encode('utf-8'), toolbox.pathName, 'exec')
File "C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx", line 3976
"""MakeFeatureLayer_management(in_features, out_layer, {where_clause}, {workspace}, {field_info})

Creates a feature layer from an input feature class or layer file. The layer
that is created by the tool is temporary and will not persist after the session
ends unless the layer is saved to disk or the map document is saved.

INPUTS:
in_features (Feature Layer):
The input feature class or layer used the make the new layer. Complex feature
classes, such as annotation and dimensions, are not valid inputs to this tool.
where_clause {SQL Expression}:
An SQL expression used to select a subset of features. The syntax for the
expression differs slightly depending on the data source. For example, if you're
querying file or ArcSDE geodatabases, shapefiles, or coverages, enclose field
names in double quotes: "MY_FIELD" If you're querying personal geodatabases,
enclose fields in square brackets: [MY_FIELD] In Python, strings are enclosed in
matching single or double quotes. To create
a string that contains quotes (as is common with a WHERE clause in SQL
expressions), you can escape the quotes (using a backslash) or triple quote the
string. For example, if the intended WHERE clause is "CITY_NAME" = 'Chicago'you
could enclose the entire string in double quotes, then escape the interior
double quotes like this: " \"CITY_NAME\" = 'Chicago' " Or you could enclose the
entire string in single quotes, then escape the
interior single quotes like this: ' "CITY_NAME" = \'Chicago\' 'Or you could
enclose the entire string in triple quotes without escaping: """ "CITY_NAME" =





^
SyntaxError: invalid syntax





Any ideas?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Honored Contributor
Never tried importing built ins, not sure what the reason you would want to do that is. For what it is worth, the problem is in SP3 as well.

Test Code

import arcpy import os toolDir = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes" for file in os.listdir(toolDir):  box = os.path.join(toolDir,file)  try:   arcpy.ImportToolbox(box)  except:   print "Error found in "+file   pass


Output
<module '3d' (built-in)> <module 'analysis' (built-in)> <module 'ArcPad' (built-in)> <module 'cartography' (built-in)> Error found in Conversion Tools.tbx <module 'arc' (built-in)> <module 'interop' (built-in)> Error found in Data Management Tools.tbx <module 'edit' (built-in)> <module 'geocoding' (built-in)> <module 'ga' (built-in)> <module 'lr' (built-in)> <module 'md' (built-in)> <module 'na' (built-in)> <module 'fabric' (built-in)> <module 'samples' (built-in)> <module 'schematics' (built-in)> <module 'server' (built-in)> <module 'sa' (built-in)> <module 'stats' (built-in)> Error found in toolbox.lic <module 'ta' (built-in)>


So looks like problem importing Conversion and Data Management Toolboxes.

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Honored Contributor
Never tried importing built ins, not sure what the reason you would want to do that is. For what it is worth, the problem is in SP3 as well.

Test Code

import arcpy import os toolDir = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes" for file in os.listdir(toolDir):  box = os.path.join(toolDir,file)  try:   arcpy.ImportToolbox(box)  except:   print "Error found in "+file   pass


Output
<module '3d' (built-in)> <module 'analysis' (built-in)> <module 'ArcPad' (built-in)> <module 'cartography' (built-in)> Error found in Conversion Tools.tbx <module 'arc' (built-in)> <module 'interop' (built-in)> Error found in Data Management Tools.tbx <module 'edit' (built-in)> <module 'geocoding' (built-in)> <module 'ga' (built-in)> <module 'lr' (built-in)> <module 'md' (built-in)> <module 'na' (built-in)> <module 'fabric' (built-in)> <module 'samples' (built-in)> <module 'schematics' (built-in)> <module 'server' (built-in)> <module 'sa' (built-in)> <module 'stats' (built-in)> Error found in toolbox.lic <module 'ta' (built-in)>


So looks like problem importing Conversion and Data Management Toolboxes.
0 Kudos
StevenHaslemore
Regular Contributor
Thanks for the reply Mathew,

hadn't realised that import was redundant, maybe a hangover from an older approach.

Either way, thanks.

Steven
0 Kudos