Created
July 31, 2013 18:13
-
-
Save math314/6124586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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