双击打开exe文件就可以进入安装界面,然后点击下一步,它会自动定位你的python安装在什么地方,但是我的安装过程显示
Python version 2.7 required, which was not found in the registry.
并且还不支持手动添加目录,然后发现是python2.7没有添加到注册表的原因。
新建一个register.py 文件,把以下代码贴进去。
# script to register Python 2.0 or later for use with win32all# and other extensions that require Python registry settings## written by Joakim Loew for Secret Labs AB / PythonWare## source:# http://www.pythonware.com/products/works/articles/regpy20.htm## modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.htmlimport sysfrom _winreg import *# tweak as necessaryversion = sys.version[:3]installpath = sys.prefixregpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)installkey = "InstallPath"pythonkey = "PythonPath"pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath)def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!"if __name__ == "__main__": RegisterPy()
保存之后进入cmd,切换到存储该py文件的目录,执行python registed.py即可重新运行exe文件进行pywin32的安装
后来在pycharm中 import win32api 时报错说找不到该模块,然后我又在cmd中 import win32api 后又报错
dll load faild:%1 不是有效的win32程序
然后我发现pywin32的安装程序的名称中的32和64位并不是针对电脑的,而是python,我的电脑是64位的而python是32位的,所以我在控制面板里删除了原先安装的64位pywin32,然后安装了32位的pywin32。
除此之外,在高级设置中添加环境变量python\Lib\site-packages之后,重启下pycharm就可以在pycharm中 import win32api了。