欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

將python安裝信息加入注冊(cè)表的示例

 更新時(shí)間:2019年11月20日 09:00:03   作者:潛水的飛魚(yú)baby  
今天小編就為大家分享一篇將python安裝信息加入注冊(cè)表的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

背景

重裝系統(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)文章

最新評(píng)論