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

yipeiwu_com5年前Python基础

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

相关文章

浅谈Python的文件类型

浅谈Python的文件类型

Python的文件类型主要分为3种:源代码(source file)、字节码(byte-code file)、优化的字节码(optimized file)。这些代码都可以直接运行,不需要...

Python 中 list 的各项操作技巧

最近在学习 python 语言。大致学习了 python 的基础语法。觉得 python 在数据处理中的地位和它的 list 操作密不可分。 特学习了相关的基础操作并在这里做下笔记。...

用Python实现BP神经网络(附代码)

用Python实现BP神经网络(附代码)

用Python实现出来的机器学习算法都是什么样子呢? 前两期线性回归及逻辑回归项目已发布(见文末链接),今天来讲讲BP神经网络。 BP神经网络 全部代码 https://github.c...

Python开发的实用计算器完整实例

Python开发的实用计算器完整实例

本文实例讲述了Python开发的实用计算器。分享给大家供大家参考,具体如下: 实现功能:图形界面PyQt,输入框,+,—,*,/ ;乘方 ,开方 ,取余,清零。 1. Python代码:...

Ubuntu下Anaconda和Pycharm配置方法详解

Ubuntu下Anaconda和Pycharm配置方法详解

本文为大家分享了Ubuntu下Anaconda和Pycharm的配置方法,供大家参考,具体内容如下 1.对于Ubuntu18.04,一开始会有一个系统默认的python解释器,是3.6版...