將python安裝信息加入注冊(cè)表的示例
背景
重裝系統(tǒng),發(fā)現(xiàn)之前裝在E盤(pán)的python可以直接使用,就只是將python的安裝目錄加入到環(huán)境變量中,也一直沒(méi)有管它,今天跟天軟交互的時(shí)候發(fā)現(xiàn)一直不成功,猜測(cè)可能是沒(méi)有注冊(cè)表信息。
從網(wǎng)上找的一段代碼,直接復(fù)制運(yùn)行即可,留存?zhèn)洳椤?/p>
代碼
py3.5.2
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()
py2.*版本
''' 解決注冊(cè)問(wèn)題,pywin32安裝存在問(wèn)題 ''' 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安裝信息加入注冊(cè)表的示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
對(duì)python使用telnet實(shí)現(xiàn)弱密碼登錄的方法詳解
今天小編就為大家分享一篇對(duì)python使用telnet實(shí)現(xiàn)弱密碼登錄的方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-01-01Python unittest discover批量執(zhí)行代碼實(shí)例
這篇文章主要介紹了Python unittest discover批量執(zhí)行代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09簡(jiǎn)單了解python中對(duì)象的取反運(yùn)算符
這篇文章主要介紹了簡(jiǎn)單了解python中對(duì)象的取反運(yùn)算符,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07python strip() 函數(shù)和 split() 函數(shù)的詳解及實(shí)例
這篇文章主要介紹了 python strip() 函數(shù)和 split() 函數(shù)的詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-02-02詳解python基礎(chǔ)之while循環(huán)及if判斷
這篇文章主要介紹了python基礎(chǔ)之while循環(huán)及if判斷的相關(guān)資料,需要的朋友可以參考下2017-08-08用Python進(jìn)行簡(jiǎn)單圖像識(shí)別(驗(yàn)證碼)
這篇文章主要為大家詳細(xì)介紹了用Python進(jìn)行簡(jiǎn)單圖像識(shí)別驗(yàn)證碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01