Select to view content in your preferred language

Fatal error when running ArcGIS Server 10.2 tool, created in Python 2.7 with pyodbc

5715
11
11-13-2014 09:20 AM
IvanHuilca
Emerging Contributor
I have a scipt in Python 2.7 with the library pyodbc published as geoprocessing tool in ArcGIS Server 10.2, when running I get fatal error: import pyodbc import error: no module named pyodbc. The tool executes smoothly from ArcMap and Python IDLE. any suggestions?

0 Kudos
11 Replies
BlakeTerhune
MVP Regular Contributor

Make sure everything is the same 32-bit or 64-bit version.

0 Kudos
IvanHuilca
Emerging Contributor

Such Blake T.
it is installed the 64 bit version.

Thank You

0 Kudos
XanderBakker
Esri Esteemed Contributor

ArcGIS 10.2 uses 32 bits...

0 Kudos
NickHetrick
Frequent Contributor

Incorrect ArcGIS server is a 64bit application now since 10.2. Desktop is 32.

System Requirements

0 Kudos
IvanHuilca
Emerging Contributor

thanks for your answers, exactly 10.2 ArcGis server uses 64 bits

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ivan,

Are you sure pyodbc is available and accessible to the server?

I do have a few comments about the code itself. There are so many int-str conversions, it makes my head spin...

When reading the rows, if "Input_Sct", "Input_Ruta" and "Input_Secu" are values (integers), use this:

    Input_Sct = "%03d" % (Input_Sct,)
    Input_Ruta = "%04d" % (Input_Ruta,)
    Input_Secu = "%05d" % (Input_Secu,)

If they are strings (or numbers), do this to format them:

    Input_Sct ="{0}".format(Input_Sct).zfill(3)
    Input_Ruta ="{0}".format(Input_Ruta).zfill(4)
    Input_Secu ="{0}".format(Input_Secu).zfill(5)

Read more on formating, here: Some Python Snippets

To concatenate a string, it is better to use the format method on a string. It makes it a lot more easy to read.

To get the number if items in a list, just use:

contlist = len(lista_Ubica)

To create the where clause you could use something like this:

fldname = "clave2"
fc = "Clientes"
where = "{0} IN ('{1}')".format(arcpy.AddFieldDelimiters(fc, fldname), "','".join(lista_Ubica))

This will create a where clause with the following syntax:

clave2 IN ('123','abc','kjsjhadas')

At the end of your script you use arcpy.da.SearchCursor to get a count. Why? I think the result is the same as the arcpy.GetCount_management you perform just before...

0 Kudos
IvanHuilca
Emerging Contributor

Such xander_bakker.
Thank you very much for your kind response, I will consider your suggestions on the concatenation of string, but as you can check in my posting the error is in the pyodbc that ArcGis server does not recognize, it is installed the 64 bit version.

Thank You

Ivan

0 Kudos
NickHetrick
Frequent Contributor

Yup you will most likely need the 64bit version of pyodbc. Also I noticed you are using a DSN to access your database. You should also make sure that you have the DSN setup in the correct ODBC manager on your windows server. Most likely if you are using 64bit it should be in the 64bit manager

IvanHuilca
Emerging Contributor

That such.
We check the DSN connection and it works, I could query the data from Excel, including the tool can be run locally from ArcCatlog and allows me to issue you ArcGis Server as you can see in the attached image, the problem I think is that ArcGIS Server not recognizes the pyodbc library.

Thanks for your feedback
arccatalog_msg.jpg
Ivan

0 Kudos