You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10安装py2exe-0.6.9报错:注册表未找到Python2.7求解决

解决py2exe-0.6.9安装报错:“Python Version 2.7 required which was not found in the registry”

我之前也踩过这个坑,py2exe 0.6.9是个比较老旧的版本,它依赖从Windows注册表读取Python 2.7的安装信息,但很多时候我们的Python 2.7要么是免安装版、要么安装时没勾选注册表选项、要么64位系统下注册表路径不匹配,导致它找不到Python的位置。给你几个靠谱的解决办法:

办法一:手动给Python 2.7添加注册表项

这是最直接的修复方式,写个小脚本就能搞定:

  1. 新建一个文本文件,命名为python27_regfix.py
  2. 根据你的Python位数选择对应的代码复制进去:
    • 如果你装的是32位Python 2.7:
      import sys
      from _winreg import *
      
      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("*** 注册失败!")
                  return
              print("--- Python", version, "已成功注册到注册表!")
              return
          if (QueryValue(reg, installkey) == installpath and
              QueryValue(reg, pythonkey) == pythonpath):
              CloseKey(reg)
              print("=== Python", version, "已经在注册表中了!")
              return
          CloseKey(reg)
          print("*** 注册失败!")
          print("*** 可能存在其他Python版本冲突!")
      
      if __name__ == "__main__":
          RegisterPy()
      
    • 如果你装的是64位Python 2.7:
      注意要修改注册表路径和根键,因为32位的py2exe安装程序会去Wow6432Node下找64位Python的注册表:
      import sys
      from _winreg import *
      
      version = sys.version[:3]
      installpath = sys.prefix
      
      # 64位Python需要走Wow6432Node路径
      regpath = "SOFTWARE\\Wow6432Node\\Python\\Pythoncore\\%s\\" % (version)
      installkey = "InstallPath"
      pythonkey = "PythonPath"
      pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
          installpath, installpath, installpath
      )
      
      def RegisterPy():
          try:
              reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
          except EnvironmentError as e:
              try:
                  reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
                  SetValue(reg, installkey, REG_SZ, installpath)
                  SetValue(reg, pythonkey, REG_SZ, pythonpath)
                  CloseKey(reg)
              except:
                  print("*** 注册失败!")
                  return
              print("--- Python", version, "已成功注册到注册表!")
              return
          if (QueryValue(reg, installkey) == installpath and
              QueryValue(reg, pythonkey) == pythonpath):
              CloseKey(reg)
              print("=== Python", version, "已经在注册表中了!")
              return
          CloseKey(reg)
          print("*** 注册失败!")
          print("*** 可能存在其他Python版本冲突!")
      
      if __name__ == "__main__":
          RegisterPy()
      
  3. 打开cmd,切换到这个脚本所在的目录,运行python python27_regfix.py,看到成功提示后再去安装py2exe试试。

办法二:用easy_install或者手动指定路径安装

  1. 先给Python 2.7装个setuptools,然后在cmd里运行easy_install py2exe==0.6.9,easy_install有时候会自动处理注册表的依赖问题。
  2. 或者直接下载对应Python 2.7位数的py2exe二进制安装包(比如py2exe-0.6.9.win32-py2.7.exe),右键选择以管理员身份运行,安装过程中如果弹出路径选择,手动指定你Python 2.7的安装目录。

办法三:重新修改Python 2.7的安装设置

如果你是用安装包装的Python 2.7,找到当初的安装程序,双击运行后选择Modify(修改),然后在组件列表里找到Add Python to registry选项,确保它是勾选状态,然后完成修改步骤,这样Python会自动把信息写入注册表。

额外注意点

  • 一定要保证py2exe的版本和Python的位数完全匹配!32位Python就装32位的py2exe,64位同理,装错了也会出问题。
  • 如果是64位Windows,有时候需要用32位的cmd来安装(路径是C:\Windows\SysWOW64\cmd.exe),因为py2exe 0.6.9是32位程序,可能在64位cmd下读取注册表有问题。

内容的提问来源于stack exchange,提问作者Hicham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:05:42