python在安裝第三方模塊時候,需要將python的路徑寫入注冊表,否則會提示 ‘python version 3.8-32 required,which was not found in the registry.’此時需要查看你的注冊表
以下為檢查及寫入方法。
一、第一步先檢查python路徑是否已經寫入注冊表:
如果已經寫入路徑,用如下步驟即可安裝win32成功:
按下鍵盤的win+R彈出運行框,輸入‘regedit’回車彈出注冊表編輯器,如下:
二、再次去執行,安裝win32
三、CMD命令行驗證是否安裝成功
如下提示安裝成功
四、如第一步沒有寫入路徑,在pycham執行如下腳本將python路徑寫入注冊表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()
執行后結果:
備注:因為筆者之前不確定自己是否已經寫入路徑成功,已經百度操作執行了上面代碼,所以執行后結果如下
執行好后,回到第一步操作,將注冊表的python路徑的3.8修改成3.8-32,即可安裝win32成功