尝试在Windows 8上安装netCDF4时,"需要Python版本2.7,在注册表中找不到"错误

bog*_*dan 39 python windows install package python-2.7

我使用的是Anaconda 1.7,32位.我从这里下载了正确版本的netCDF4安装程序.

我试图将HKEY_LOCAL_MACHINE\SOFTWARE\Python文件夹复制到HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node中.没运气.

有谁知道为什么会发生这种情况?Anaconda安装在默认位置,C:/.

是的,我知道Anaconda在软件包列表中有netCDF4 - 但如果仔细观察,它只适用于Mac和Linux.

1''*_*1'' 94

如果要安装的位数与Python版本的位数不同,则会发生此错误.要查看Python安装是32位还是64位,请参阅此处.

SourceForge或python.org上提供的一些超级包(例如Scipy)适用于32位系统,有些适用于64位系统.看到这个答案.在Windows中,卸载32位并安装64位版本(反之亦然,如果您的安装是32位)可以解决问题.


duh*_*ime 53

使用.exe安装Python软件包时遇到了同样的问题(因为我使用的是Anaconda而且没有将Python添加到注册表中).我通过运行此脚本修复了问题:

#
# script to register Python 2.0 or later for use with 
# Python extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html

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()
Run Code Online (Sandbox Code Playgroud)

  • 你刚刚给我一个痛苦的世界,非常感谢! (6认同)
  • 对于python 3,只需在`print`调用周围添加括号,并用`import winreg`替换`import _winreg`,它完美地运行 (4认同)
  • 神圣的废话男人这个答案值得更多的爱. (3认同)
  • 真的很有帮助,非常感谢你! (2认同)
  • 你将被命名为"甲骨文" (2认同)
  • 上帝祝福你。谢谢 (2认同)

pep*_*epr 3

只需从官方 Python 下载页面下载Python 2.7.6 Windows Installer,然后启动安装包。

  • 这不太有帮助。同样的错误仍然可能发生,例如,如果您想安装两个版本的 Python,然后 Windows 安装程序同样失败。我认为最好看看这里的原因是什么。 (8认同)