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

yipeiwu_com4年前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正则表达式实现简易计算器功能。分享给大家供大家参考,具体如下: 需求:使用正则表达式完成一个简易计算器。 功能:能够计算简单的表达式。 如:1*2*((1+...

python实现向微信用户发送每日一句 python实现微信聊天机器人

分享几个Python针对微信的小工具,供大家参考,具体内容如下 用Python实现向微信用户发送每日一句 # -*- coding:utf-8 -*- from __future__...

Python实现的金山快盘的签到程序

复制代码 代码如下:__author__ = 'clownfish'#coding:utf-8import urllib2,urllib,cookielib,json username...

wxpython+pymysql实现用户登陆功能

wxpython+pymysql实现用户登陆功能

wxpython最为一款python GUI库,由于简单和轻便外加强大的功能而受到很多python爱好者的喜爱,pymysql作为python3.x版本连接mysql库,应用也非常广泛。...

对python多线程中互斥锁Threading.Lock的简单应用详解

对python多线程中互斥锁Threading.Lock的简单应用详解

一、线程共享进程资源 每个线程互相独立,相互之间没有任何关系,但是在同一个进程中的资源,线程是共享的,如果不进行资源的合理分配,对数据造成破坏,使得线程运行的结果不可预期。这种现象称为“...