如何导入win32api
我正在尝试使用一些 python-2.1 代码来控制另一个程序(ArcGIS)。我使用的python版本是2.5。当我运行代码时,我收到以下错误消息。
<type'exceptions.ImportError'>: No module named win32api
Failed to execute (polyline2geonetwork2).
我尝试安装 pywin32-214.win32-py2.5.exe 但仍然收到相同的错误消息。我不知道我是否需要对我原来的 python 安装做任何事情,所以它知道我已经安装了这个。
我认为我的代码有问题的部分如下:
import win32com.client, sys, string, os, re, time, math
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
conn = win32com.client.Dispatch(r'ADODB.Connection')
感谢您的帮助 - 我对 python 很陌生。
I'm trying to use some python-2.1 code to control another program (ArcGIS). The version of python I am using is 2.5. I am getting the following error message when I run the code.
<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 anything to my original python install so it knows that I have installed this.
I think the problematic part of my code is the following:
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 quite new to python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 sys.path
和 winapi.py 位于 C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp 中。
请注意,该目录未在您的 sys.path 中列出。为了使事情正常工作,您需要将 C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp 放入 sys.path 中。
看来 winapi.py 尚未安装。它位于 test\build...\temp 目录中。
我对Windows+Python了解不多。也许 winapi.py 附带了一些文档,其中解释了如何实现安装。
一个快速(但丑陋)的修复方法是手动将所需的目录插入到 sys.path 中。
我的意思是,您可以编辑 polyline2geonetwork.py 并将其放在
文件顶部附近。
Your sys.path is
and winapi.py is located in C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp.
Notice that this directory is not listed in your sys.path. To get things working, you'll need to put C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp in your sys.path.
It appears winapi.py is not yet installed. It is in a test\build...\temp directory.
I don't know much about Windows+Python. Maybe there is documentation that came with winapi.py which explains how the installation is suppose to be achieved.
A quick (but ugly) fix is to manually insert the needed directory into sys.path.
By this I mean, you can edit polyline2geonetwork.py and put
near the top of the file.
在导入之前打印出
sys.path
并确保其中有win32com
的路径print out
sys.path
right before the import and make sure the path towin32com
is in there