Skip to content

Instantly share code, notes, and snippets.

@math314
Created July 31, 2013 18:13
Show Gist options
  • Select an option

  • Save math314/6124586 to your computer and use it in GitHub Desktop.

Select an option

Save math314/6124586 to your computer and use it in GitHub Desktop.
private string GetPythonPath()
{
Func<Microsoft.Win32.RegistryKey, string> get_path = key =>
{
using (var sub_key = key.OpenSubKey(@"SOFTWARE\Python\PythonCore\2.7\InstallPath"))
{
if (sub_key == null)
return null;
var path = (string)sub_key.GetValue(null);
return path;
}
};
if (System.Environment.Is64BitOperatingSystem)
{
using (var hklm = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64))
{
var path64 = get_path(hklm);
if (path64 != null) return path64;
}
}
var path32 = get_path(Microsoft.Win32.Registry.CurrentUser);
if (path32 != null) return path32;
throw new NotSupportedException("Python2.7がinstallされていません。");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment