Hi,
I've built a model with model builder. When I run it from model builder it works but now that i've exported it to python, it doesn't work...
Here is my model:
# Import arcpy module
import arcpy
# Load required toolboxes
arcpy.ImportToolbox("C:/Users/w2sohi/Desktop/test/box.tbx","box")
# Local variables:
INTER = "C:\\Users\\w2sohi\\Desktop\\test\\INTER"
# Process: Recréer le localisateur d’adresses
arcpy.RebuildAddressLocator_box(INTER)
It seems that there's a problem with: arcpy.ImportToolbox("C:/Users/w2sohi/Desktop/test/box.tbx","box")
I have these error messages:
Traceback (most recent call last):
File "C:\Users\w2sohi\Desktop\test\recreer.py", line 13, in <module>
arcpy.ImportToolbox("C:/Users/w2sohi/Desktop/test/box.tbx","box")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 90, in ImportToolbox
return import_toolbox(input_file, module_name)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 441, in import_toolbox
mymodule = generate_toolbox_module(toolbox, None, False, False, False, module_name, use_alt_alias)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 399, in generate_toolbox_module
use_alt_alias))
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 391, in <genexpr>
code = u"\n".join(line if isinstance(line, unicode)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 311, in code_for_toolbox
yield "__all__ = %r" % ([str(tool.name) for tool in toolbox.tools],)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 3: ordinal not in range(128)
Thank you very much!
Guillaume
Solved! Go to Solution.
So it looks like you have a system tool and a model in your toolbox. The problem is that the model within your toolbox is named "Modèle". When you call ImportToolbox this will cause a conflict because identifiers in python 2.X don't support using he character è. If you remove the è the toolbox imports just fine.
oh!
Well done Freddie, thank you!