本文介绍了无法在 Python 2.7.9 虚拟环境中导入 _winreg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows 7 64 位、python 2.7.9 x64 的虚拟环境中运行应用引擎应用程序.

I'm running an app engine application in a virtual environment on windows 7 64bit, python 2.7.9 x64.

这是堆栈跟踪:

    p_system = platform.system()
  File "C:Python27libplatform.py", line 1310, in system
    return uname()[0]
  File "C:Python27libplatform.py", line 1206, in uname
    release,version,csd,ptype = win32_ver()
  File "C:Python27libplatform.py", line 597, in win32_ver
    import _winreg
  File "C:Program Files (x86)Googlegoogle_appenginegoogleappengine	oolsdevappserver2pythonsandbox.py", line 945, in load_module
    raise ImportError('No module named %s' % fullname)
  ImportError: No module named _winreg

但是,它从 cli(在 venv 之外)运行得很好:

However, it works just fine from cli (outside venv):

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:UsersAdmin>python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _winreg
>>> import platform
>>> platform.system()
'Windows'
>>>

为什么会这样?我该怎么做才能解决这个问题?

Why does this happen? What can I do to fix this?

推荐答案

Module _winreg, as 文档 说,存在是为了将 Windows 注册表 API 暴露给 Python".

Module _winreg, as the docs say, exists to "expose the Windows registry API to Python".

App Engine 不提供Windows 注册表 API"(也不提供任何其他 Windows 特定的 API).因此,它的 sandbox 块尝试 import 模块 - 请注意,在堆栈跟踪的末尾,该异常是在 sandbox.py 模块中故意引发的 App Engine SDK.

App Engine does not supply a "Windows registry API" (nor any other Windows-specific API). Therefore, its sandbox blocks attempts to import the module -- note, at the end of your stack trace, that the exception is deliberately raised in module sandbox.py of the App Engine SDK.

Python 的虚拟环境"在这里没有任何作用——这完全与 App Engine 相关.

Python's "virtual env" plays no part here -- it's all about App Engine.

请说明您在部署 GAE 应用程序后尝试使用 _winreg 完成的任务——假设它已部署到 Linux 服务器(尽管 GAE 运行时也不提供特定于 Linux 的 API:-),所以附近的任何地方都没有 Windows Registry API...

Please clarify what task you're trying to accomplish with _winreg once your GAE app is deployed -- assume it's deployed to Linux servers (although the GAE runtime doesn't supply Linux-specific APIs either:-), so there is no Windows Registry API anywhere in the neighborhood...

这篇关于无法在 Python 2.7.9 虚拟环境中导入 _winreg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:21