Python import error

I am trying to use python-2.1 code to control another program (ArcGIS). The python version I'm using is 2.5. When you run the code, the following error message appears.

<type'exceptions.ImportError'>: No module named win32api Failed to execute (polyline2geonetwork2). 

I tried installing pywin32-214.win32-py2.5.exe, but I still get the same error message. I can't figure out if I need to do something for my initial python installation, so it knows that I installed this.

I think the problem part of my code is as follows:

 import win32com.client, sys, string, os, re, time, math gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") conn = win32com.client.Dispatch(r'ADODB.Connection') 

Thanks for your help. I am new to python.

+4
source share
3 answers

Your sys.path is

 ['C:\\Documents and Settings\\david\\My Documents\\GIS_References\\public\\funconn_public', 'C:\\Python25\\Lib\\idlelib', 'C:\\Program Files\\ArcGIS\\bin', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages', 'C:\\Python25\\lib\\site-packages\\win32', 'C:\\Python25\\lib\\site-packages\\win32\\lib', 'C:\\Python25\\lib\\site-packages\\Pythonwin'] 

and winapi.py is located in the folder C: \ Python25 \ Lib \ site-packages \ isapi \ test \ build \ bdist.win32 \ winexe \ temp.

Please note that this directory is not listed in your sys.path. To make everything work, you need to put C: \ Python25 \ Lib \ site-packages \ isapi \ test \ build \ bdist.win32 \ winexe \ temp in your sys.path.

It looks like winapi.py is not installed yet. It is located in the test \ build ... \ temp directory. I don't know anything about Windows + Python. Perhaps there is documentation that comes with winapi.py that explains how the installation is supposed to be achieved.

A quick (but ugly) fix is ​​to manually insert the desired directory into sys.path. By that I mean, you can edit the polyline2geonetwork.py file and put

 import sys sys.path.append(r'C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp') 

at the top of the file.

+2
source

print sys.path right before importing and make sure that win32com is there

+1
source

everyone, please read the error message: "There is no module named win32api ", i.e. not win32com

Put some diagnostic materials at the top of your script, for example.

 import sys print sys.version print sys.path print sys.argv[0] 

and cut the rest of your script to the minimum necessary to reproduce the problem.

Show us (a) script (b) the output, the exact trace and error information reproduced by copying / pasting into and edited version of your question, i.e. do not retype it.

0
source

All Articles