安裝python的pywin32安裝不了,提示找不到py3.6-32

安裝python的pywin32安裝不了,提示找不到py3.6-32

首先我本身的py3.6是64位版本的,這是pywin32模塊的下載地址python

裏面有各類版本的,首先我先下了64位的3.6版本的,結果提示這裏寫圖片描述這裏寫圖片描述markdown

解決方法(親測有效):post

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()

運行這段代碼之後能夠自動將py3.6安裝目錄直接添加進註冊表,檢查了下注冊表,的確出現了。spa

而後我在試了下64位的exe文件,仍是提示找不到註冊表。code

而後打開註冊表,win+R鍵,以後輸入regedit 
找到這裏這裏寫圖片描述 
將3.6改成3.6-32,這樣就能夠進行安裝了blog

相關文章
相關標籤/搜索