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

脚本专栏 发布日期:2024/10/24 浏览次数:1

正在浏览:将python2.7添加进64位系统的注册表方式

解决问题: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位系统的注册表方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。