如何将python安装信息加入注册表-创新互联

这篇文章将为大家详细讲解有关如何将python安装信息加入注册表,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联是一家专业提供平果企业网站建设,专注与网站制作、网站建设、HTML5、小程序制作等业务。10年已为平果众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

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安装信息加入注册表就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

文章名称:如何将python安装信息加入注册表-创新互联
文章位置:https://www.cdcxhl.com/article26/cciocg.html

成都网站建设公司_创新互联,为您提供网站排名App开发品牌网站设计网站导航响应式网站品牌网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都做网站