def get_previous_install_prefixes(pyversion, arch, allusers=True):
"""Returns a list of prefixes for all old installations of this arch so that
they can be removed from PATH if present. Note, it would be preferable to
uninstall them properly instead.
"""
if allusers:
# All Users
key, subkey = (reg.HKEY_LOCAL_MACHINE, r'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\')
else:
# Just Me
key, subkey = (reg.HKEY_CURRENT_USER, r'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\')
keylist = []
# We ignore pyversion and instead look for any *conda installations.
regex = re.compile('Python \S+ \(\S+conda[0-9]+ \S+ '+arch+'\)')
_reg_query_sub_keys(key, subkey, keylist)
results = []
for uninstsubkey in keylist:
final_part = os.path.basename(uninstsubkey.rstrip('\\'))
if regex.match(final_part):
try:
with reg.OpenKeyEx(key, uninstsubkey, 0,
reg.KEY_QUERY_VALUE) as keyhandle:
reg_value = reg.QueryValueEx(keyhandle, 'UninstallString')
results.append(os.path.dirname(re.sub(r'^"|"$', '', reg_value[0])))
except:
pass
return results
评论列表
文章目录