下載舊版
https://sourceforge.net/projects/pywin32/files/pywin32/
下載新版
https://github.com/mhammond/pywin32/releases
源碼安裝出現下面報錯,暫不推薦
RuntimeError: Can't find the Windows SDK
最簡單的方法就是下載二進制文件
https://github.com/mhammond/pywin32/releases
查看python在注冊表的路徑
[HKEY_CURRENT_USER\Software\Python\Pythoncore\3.6\InstallPath] @="C:\\Python26" [HKEY_CURRENT_USER\Software\Python\Pythoncore\3.6\PythonPath] @="C:\\Python26;C:\\Python26\\Lib\\;C:\\Python26\\DLLs\\"
安裝pywin32出現Python Version 3.6 required which was not found in the registry,表示注冊表里沒有python3.6的安裝路徑,出現這個問題是因為我是直接從另一台電腦拖過來的,不是正規安裝
在注冊表中寫入python3.6的安裝路徑
解決方法
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()
然后再運行pywin32安裝文件即可
