1.先下载pywin32对于的版本
下载地址:python for windows extensions
2.选择自己对应的版本,我的是python3.5版本
注意注意注意:此处一定要看清楚自己的python是什么版本
cmd中输入python查看
C:\Users\Administrator\Desktop>python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 5 2016, 11:41:13) [MSC v
.1900 64 bit (AMD64)] on win32
我这是64 bit的python 所以要下载64bit的pywin32
3.进入界面后,会自动倒数5秒 然后开始下载
4.安装pywin32-----双击pywin32的exe文件,若提示报错说:没有注册 ,如下图
此时,新建一个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.html import sys from winreg import * # tweak as necessary
version = sys.version[:3]
installpath = sys.prefix regpath = "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 后又报错 那么请回看第二步,查看是不是pywin32 的位数版本下载错误了,错了请重新安装pywin32 同时配置环境变量
https://jingyan.baidu.com/article/915fc414c88be051394b2093.html 配置环境变量:
检查安装结果,在python命令行输入import win32api,
如果没有报错说明安装完成
如果报错说明PYTHONPATH环境变量没有配置
配置PYTHONPATH环境变量,将python安装目录下lib目录中的site-packages路径添加到PYTHONPATH环境变量
配置好以后新开一个cmd窗口 或者 重启pycharm后 import win32api