python win32api手册可以直接调用win32的api吗

ImportError: No module named win32api | Python | Python
this category
ImportError: No module named win32api
Oct&9,&&PM
Post #1 of 4
(4632 views)
ImportError: No module named win32api
Hi, I was trying to run a python script from my DOS prompt. I got the following error message: E:\&installer.py Traceback (most recent call last):
File "E:\installer.py", line 101, in ?
import win32api, win32file ImportError: No module named win32api
Can anyone tell me what this error message means? My OS is Windows XP. is win32api something that's only available on windows2000, but not on XP?
Thank you in advance! eddy
Oct&9,&&PM
Post #2 of 4
(4587 views)
ImportError: No module named win32api
eddie wang wrote:
& Hi, I was trying to run a python script from my DOS prompt. I got the & following error message: & E:\&installer.py & Traceback (most recent call last): &
File "E:\installer.py", line 101, in ? &
import win32api, win32file & ImportError: No module named win32api &
That means you probably don't have Mark Hammond's Win32 extensions. It
appears the script your are trying to run is looking for the Windows API
You can download the win32 extensions from the following URL and it should
give you the win32* modules:
starship.python.net/crew/mhammond/win32/Downloads.html
Mark Nenadov, Freelance Software Developer web:
e-mail: mark [at] freelance-developer
Oct&10,&&AM
Post #3 of 4
(4589 views)
ImportError: No module named win32api
eddie wang wrote:
& Hi, I was trying to run a python script from my DOS prompt. I got the & following error message: & E:\&installer.py & Traceback (most recent call last): &
File "E:\installer.py", line 101, in ? &
import win32api, win32file & ImportError: No module named win32api &
& Can anyone tell me what this error message means? My OS is Windows XP. & is win32api something that's only available on windows2000, but not on & XP?
win32api should work fine on XP just as it does in Win2K, but it's not part of the stsndard Python distribution.
You can download it from the page of its author, Mark Hammond:
Be sure to download the right version -- e.g. latest stable one for Python 2.2 is:
Each win32all version is a self-unpacking, self-installing executable.
Oct&10,&&PM
Post #4 of 4
(4586 views)
ImportError: No module named win32api
Alex and Mark, Thank you so much for the information! it worked.
&&&&Announce
&&&&Python
&&&&Checkins
Interested in having your list archived?
Powered by Gossamer Threads Inc.您所在的位置: &
使用ctypes和pywin32访问原生API
使用ctypes和pywin32访问原生API
高弘扬/卫莹 译
清华大学出版社
《Python项目开发实战》第2章Python脚本,本章,你会学到如何使用Python模块检查用户设置以及目录和文件的访问级别,为一个操作设置正确的环境,以及在脚本中启动和控制外部程序。本节为大家介绍使用ctypes和pywin32访问原生API。
2.4& 使用ctypes和pywin32访问原生API
一些应用或操作系统函数不容易通过常规Python代码访问,因为没有可以从Python中调用的Python API或暴露出来的用户友好的操作。ctypes模块可以提供一个可选的访问方法。这种方法向Python提供了用于构建应用的C代码库。在Windows中,这些库通常是一组DLL文件。而在UNIX中,它们是一组共享对象库。ctypes让你将这些库加载到你的应用中,并直接从Python中调用它们的函数。当然,这仅在你知道库中有哪些函数、需要什么参数以及返回值时才有效。这可能被发布,因为需要反复试验或者逆向工程。反过来,逆向工程可能被生产者或供应商所禁止。然而,如果库有一个已发布的接口,ctypes就提供了一种虽不常规但有效的访问方法。
注意:使用ctypes需要一些C语言编程的基础知识。如果没有这项技术,你可能想跳过这部分,因为它可能没有什么意义。另一方面,浏览一下它能让你知道它有哪些用途,有些你可能会需要。
当使用ctypes时,你就把Python解释器的安全网抛在一边了。记住,你在操作原始操作系统库时,有时会直接访问内存地址。这些库也直接操作原始文件系统和输入/输出流,所以它们可能不会展示你使用IDE,比如IDLE或Pythonwin时所期待的结果。
如果犯了错误,则可能会轻易导致Python解释器崩溃。在极端情况下,甚至可能导致操作系统崩溃。这就是为什么在万不得已的情况下你才使用ctypes和类似东西的原因。只有当其他方法都失败时,才去使用它。
另一个包是pywin32,它在ActiveState发行版本的Python中被默认安装。在其他发行版本中也可以下载安装。这个包提供了对Windows原生库的访问,尤其是对任何Microsoft组件对象模型(COM)接口的访问。特定于Windows,pywin32要比ctypes更易用。一般来说,ctypes可以在任何操作系统上工作。对于使用ctypes的警告同样可以应用在pywin32上。
&喜欢的朋友可以添加我们的微信账号:
51CTO读书频道二维码
51CTO读书频道活动讨论群:【责任编辑: TEL:(010)】&&&&&&
关于&&的更多文章
本书介绍了Python应用在各个领域中的一些使用技巧和方法,其主题
本书描述了黑客用默默无闻的行动为数字世界照亮了一条道路的故事。
讲师: 4人学习过讲师: 3人学习过讲师: 20人学习过
经证实的PL/SQL优化解决方案
在《Oracle PL/SQL性能
《Oracle Mobile Application Framework开发指南--构
精通Java WebSocket应用开发
充分利用最先进的通信技
本书主要介绍了SQL的数据库应用和开发技术,内容涉及关系数据库和SQL概述,SQL环境,SQL对于数据表的操作,数据库查询知识,SQL
51CTO旗下网站

我要回帖

更多关于 python调用win api 的文章

 

随机推荐