最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

將python安裝信息加入注冊表的示例

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

背景

重裝系統(tǒng),發(fā)現(xiàn)之前裝在E盤的python可以直接使用,就只是將python的安裝目錄加入到環(huán)境變量中,也一直沒有管它,今天跟天軟交互的時候發(fā)現(xiàn)一直不成功,猜測可能是沒有注冊表信息。

從網(wǎng)上找的一段代碼,直接復(fù)制運行即可,留存?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.*版本

'''
解決注冊問題,pywin32安裝存在問題
'''

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安裝信息加入注冊表的示例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

旅游| 虹口区| 临安市| 竹溪县| 贞丰县| 昌平区| 什邡市| 宜都市| 卢氏县| 金溪县| 阳西县| 卢龙县| 克东县| 大荔县| 龙海市| 福海县| 肇庆市| 兴海县| 姚安县| 新营市| 兴海县| 山西省| 文安县| 合肥市| 徐水县| 遵义市| 景德镇市| 清流县| 山东| 右玉县| 富裕县| 永登县| 都安| 奉贤区| 土默特左旗| 柳州市| 灵山县| 逊克县| 囊谦县| 荥阳市| 抚宁县|