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

2024-05-21 01:49:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我用水蟒1.7,32位。我从here下载了netCDF4安装程序的正确版本。

我试图将HKEY_LOCAL_MACHINE\SOFTWARE\Python文件夹复制到HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node。运气不好。

有人知道为什么会这样吗?Anaconda安装在默认位置C:/。

是的,我知道Anaconda在软件包列表中有netCDF4,但是如果仔细观察,它只提供给Mac和Linux。


Tags: 版本文件夹列表heremaclocalsoftwareanaconda
3条回答

我在使用.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()

只需从the official Python download page下载Python 2.7.6 Windows Installer,然后启动安装包。

如果安装的包的位与Python版本不同,则可能发生此错误。要查看Python安装是32位还是64位,请参见here

SourceForge或python.or g上提供的一些超级包(例如,用于Scipy)用于32位系统,有些用于64位系统。见this answer。在Windows中,卸载32位并安装64位版本(如果安装为32位,则反之亦然)可以解决此问题。

相关问题 更多 >