广告
返回顶部
首页 > 资讯 > 后端开发 > Python >将python2.7添加进64位系统的注册表方式
  • 582
分享到

将python2.7添加进64位系统的注册表方式

python2.764位注册表 2022-06-04 23:06:40 582人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

解决问题:python2.7无法在注册表中被识别,即在安装NumPy和SciPy等出现“Python version 2.7 required, which was not found in reGISter”的问题。

解决问题:python2.7无法在注册表中被识别,即在安装NumPy和SciPy等出现“Python version 2.7 required, which was not found in reGISter”的问题。

解决方法:新建一个“register.py”的文件,复制以下内容,通过powershell的命令“python register.py”运行,看到“Python 2.7 is now registered!”即可。


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()

以上这篇将python2.7添加进64位系统的注册表方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们nDsFTko

--结束END--

本文标题: 将python2.7添加进64位系统的注册表方式

本文链接: https://www.lsjlt.com/news/20733.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作