无法在Python 2.7.9虚拟环境中导入_winreg

Fil*_*und 2 python windows google-app-engine winreg python-2.7

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

这是堆栈跟踪:

    p_system = platform.system()
  File "C:\Python27\lib\platform.py", line 1310, in system
    return uname()[0]
  File "C:\Python27\lib\platform.py", line 1206, in uname
    release,version,csd,ptype = win32_ver()
  File "C:\Python27\lib\platform.py", line 597, in win32_ver
    import _winreg
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\python\sandbox.py", line 945, in load_module
    raise ImportError('No module named %s' % fullname)
  ImportError: No module named _winreg
Run Code Online (Sandbox Code Playgroud)

但是,从cli(在venv之外)它可以正常工作:

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

C:\Users\Admin>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'
>>>
Run Code Online (Sandbox Code Playgroud)

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

Ale*_*lli 6

_winreg正如文档所说,模块存在于"将Windows注册表API暴露给Python".

App Engine不提供"Windows注册表API"(也不提供任何其他Windows特定的API).因此,它的沙箱块会尝试import模块 - 请注意,在堆栈跟踪结束时,sandbox.pyApp Engine SDK的模块中会故意引发异常.

Python的"虚拟环境"在这里不起作用 - 它都是关于App Engine的.

请说明_winreg一旦部署GAE应用程序后您要完成的任务- 假设它已部署到Linux服务器(尽管GAE运行时不提供特定于Linux的API :-),因此没有Windows Registry API附近的任何地方......