You're silencing the ImportError
.
try:
import _winreg as winreg
except ImportError:
pass
winreg
is most likely not getting imported here, hence the NameError
: the winreg
name was never assigned because import failed.
You could remove the try
/ except
block to confirm what's happening.
Since you want to support Python 3, what you're most likely looking for is:
try:
import _winreg as winreg # Try importing on Python 2
except ImportError:
import winreg # Fallback to Python 3 (if this raises an Exception, it'll escalate)