Search code examples
pythonjythonwinreg

Accessing winreg from jython


Why can't access the _winreg module from jython?

c:\>python  
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.  
import _winreg  

c:\>jython  
Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_31
Type "help", "copyright", "credits" or "license" for more information.  
import _winreg  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named _winreg

Solution

  • _winreg is not available in Jython.

    In CPython on Windows, _winreg is a built-in module (mirroring the underlying Windows API) that is compiled into the Python interpreter. This can be verified by checking the sys.builtin_module_names property.

    See also Python alternative to _winreg.