我在 Windows 7 64 位、python 2.7.9 x64 的虚拟环境中运行 App Engine 应用程序。
这是堆栈跟踪:
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
但是,它在 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'
>>>
为什么会这样?我该怎么做才能解决这个问题?
最佳答案
模块 _winreg
,为 the docs比如说,存在是为了“将 Windows 注册表 API 公开给 Python”。
App Engine 不提供“Windows 注册表 API”(也不提供任何其他特定于 Windows 的 API)。因此,它的 sandbox 阻止尝试import
模块——请注意,在堆栈跟踪的末尾,模块 sandbox.py 中有意引发异常
App Engine SDK。
Python 的“虚拟环境”在这里没有任何作用——一切都与 App Engine 有关。
请说明您在部署 GAE 应用程序后尝试使用 _winreg
完成的任务——假设它已部署到 Linux 服务器(尽管 GAE 运行时也不提供特定于 Linux 的 API :-),所以附近的任何地方都没有 Windows Registry API...
关于python - 无法在 Python 2.7.9 虚拟环境中导入 _winreg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28640983/