【问题标题】:How to avoid "no module named _winreg" issue with Google Cloud SDK and Python API on Windows?如何避免 Windows 上的 Google Cloud SDK 和 Python API 出现“没有名为 _winreg 的模块”问题?
【发布时间】:2017-07-20 20:12:50
【问题描述】:

在 Windows 下使用 Google Cloud SDK 和 Python 启动本地开发服务器时,尝试加载“platform.py”时会引发错误,因为此模块正在尝试导入“_winreg”。显然,这是由于应用引擎的沙盒:

_winreg 是一个用于访问 Windows 注册表服务的库。它在您的 Python shell 中可用,因为您在 Windows 机器上运行,但是当您将应用程序上传到 App Engine 生产服务器时它将不可用 - 因此,它在开发服务器中也不可用。 [reference]

如何避免这个问题?

【问题讨论】:

    标签: python-2.7 google-cloud-platform


    【解决方案1】:

    由于 App Engine 不使用通过 _winreg 加载的变量,我可以将 platform.py 中的相关部分注释掉:

    # Emulation using _winreg (added in Python 2.0) and
    # sys.getwindowsversion() (added in Python 2.3)
    GetVersionEx = sys.getwindowsversion
    '''
    import _winreg
    RegQueryValueEx = _winreg.QueryValueEx
    RegOpenKeyEx = _winreg.OpenKeyEx
    RegCloseKey = _winreg.CloseKey
    HKEY_LOCAL_MACHINE = _winreg.HKEY_LOCAL_MACHINE
    '''
    VER_PLATFORM_WIN32_WINDOWS = 1
    VER_PLATFORM_WIN32_NT = 2
    VER_NT_WORKSTATION = 1
    VER_NT_SERVER = 3
    REG_SZ = 1
    

    这似乎对 App Engine 没有影响,而且它消除了错误!

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      • 2015-06-03
      • 1970-01-01
      • 2019-01-30
      相关资源
      最近更新 更多