Failed to import _winreg in Python 2.7.9 virtual environment

I am running an application for applications with applications in a virtual environment on Windows 7 64bit, python 2.7.9 x64.

Here's the stacktrace:

    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

However, it works fine from cli (outside of 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'
>>>

Why is this happening? What can I do to fix this?

+2
source share
4 answers

The module _winreg, as docs says, exists to "expose the Windows Python Windows registry."

App Engine "API Windows" ( - API Windows). import - , , sandbox.py SDK App Engine.

Python "virtual env" - App Engine.

, _winreg GAE - , Linux ( GAE Linux- API:-), API Windows...

+6

, Google, , , :

  • : <sdk_root>\google\appengine\tools\devappserver2\python\sandbox.py
  • _WHITE_LIST_C_MODULES = [xxx]
  • :

'_winreg',

'_ctypes',

, python -m pip install google-cloud

+4

, , GAE , , , SERVER_SOFTWARE ​​ , "Dev".

( GAE), :

import os
os.environ['SERVER_SOFTWARE'] = 'Dev'

. , , , .

+1

.

As mentioned above, the GAE sandbox on Windows blocks some routines or libraries, even built-in ones, because it is designed for a Unix-like platform.

I opened a message for Google Team and they exchanged a workaround:

https://issuetracker.google.com/issues/38290292

This working method worked well.

+1
source

Source: https://habr.com/ru/post/1014325/


All Articles