Legacy build tools and installation utilities often fail to detect Python on Windows when querying the system registry, resulting in errors such as "Python version 2.7 required, which was not found in the registry." This typically occurs because the installer expects specific registry paths under HKEY_CURRENT_USER, but the installation was performed system-wide or in a 64-bit environment.
Manually populating the expected registry keys resolves the detection failure. Execute the following script using the target Python interpreter to write the necessary configuration values.
import sys
try:
import winreg as reg_mod
except ImportError:
import _winreg as reg_mod
TARGET_VER = sys.version[:3]
EXEC_PRE = sys.prefix
CORE_PATH = "SOFTWARE\\Python\\Pythoncore\\%s\\" % TARGET_VER
INST_KEY = "InstallPath"
PATH_KEY = "PythonPath"
NEW_VALS = "%s;%s\\Lib\\;%s\\DLLs\\" % (EXEC_PRE, EXEC_PRE, EXEC_PRE)
def sync_registry():
user_key = reg_mod.HKEY_CURRENT_USER
hnd = None
created = False
try:
hnd = reg_mod.OpenKey(user_key, CORE_PATH)
except EnvironmentError:
try:
hnd = reg_mod.CreateKey(user_key, CORE_PATH)
created = True
except EnvironmentError:
print("Failed to generate registry path.")
return
cur_inst = reg_mod.QueryValue(hnd, INST_KEY)
cur_path = reg_mod.QueryValue(hnd, PATH_KEY)
if cur_inst == EXEC_PRE and cur_path == NEW_VALS:
print("Python %s registration verified." % TARGET_VER)
return
try:
reg_mod.SetValue(hnd, INST_KEY, reg_mod.REG_SZ, EXEC_PRE)
reg_mod.SetValue(hnd, PATH_KEY, reg_mod.REG_SZ, NEW_VALS)
print("Updated configuration for Python %s." % TARGET_VER)
except Exception as e:
print("Registration skipped due to permission restrictions: %s" % e)
finally:
if hnd and created:
reg_mod.CloseKey(hnd)
if __name__ == "__main__":
sync_registry()
Run the utility directly from the command prompt or within an interactive session. The tool verifies existing entries before modifying the database, preventing redundant writes.
C:\> python register_fix.py
Updated configuration for Python 2.7.
Alternatively, the message confirms the operation succeeded. Subsequent attempts to install dependencies like setuptools, pywin32, or older binary wheels will automatically locate the interpreter through the updated lookup paths.
This discrepancy originates from Windows architecture permissions. When a 32-bit Python distribution is installed for "All Users" on a 64-bit operating system, configuration data defaults to the machine-level hive (HKEY_LOCAL_MACHINE). Setup wizards scanning the current user hive cannot find these entries. Choosing the "Just Me" installation option confines settings to the user hive, avoiding this issue entirely. For existing multi-user setups, running the provided script forces synchronization to the expected location.