예제 #1
0
        private static PythonVersion TryGetCPythonPath(PythonLanguageVersion version, RegistryKey python, bool x64)
        {
            if (python != null)
            {
                string versionStr = version.ToString().Substring(1);
                string id         = versionStr = versionStr[0] + "." + versionStr[1];
                if (!x64 && version >= PythonLanguageVersion.V35)
                {
                    versionStr += "-32";
                }

                using (var versionKey = python.OpenSubKey(versionStr + "\\InstallPath")) {
                    if (versionKey != null)
                    {
                        var installPath = versionKey.GetValue("");
                        if (installPath != null)
                        {
                            var path = Path.Combine(installPath.ToString(), "python.exe");
                            var arch = NativeMethods.GetBinaryType(path);
                            if (arch == ProcessorArchitecture.X86)
                            {
                                return(x64 ? null : new PythonVersion(
                                           path,
                                           version,
                                           CPythonInterpreterFactoryConstants.GetIntepreterId(
                                               "PythonCore",
                                               arch,
                                               id
                                               ),
                                           false,
                                           false,
                                           true
                                           ));
                            }
                            else if (arch == ProcessorArchitecture.Amd64)
                            {
                                return(x64 ? new PythonVersion(
                                           path,
                                           version,
                                           CPythonInterpreterFactoryConstants.GetIntepreterId(
                                               "PythonCore",
                                               arch,
                                               id
                                               ),
                                           true,
                                           false,
                                           true
                                           ) : null);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                }
            }
            return(null);
        }
예제 #2
0
        private static PythonVersion GetCPythonVersion(PythonLanguageVersion version, bool x64 = false)
        {
            if (!x64)
            {
                foreach (var baseKey in new[] { Registry.LocalMachine, Registry.CurrentUser })
                {
                    using (var python = baseKey.OpenSubKey(PythonCorePath)) {
                        var res = TryGetCPythonPath(version, python, x64);
                        if (res != null)
                        {
                            return(res);
                        }
                    }
                }
            }

            if (Environment.Is64BitOperatingSystem && x64)
            {
                foreach (var baseHive in new[] { RegistryHive.LocalMachine, RegistryHive.CurrentUser })
                {
                    var python64 = RegistryKey.OpenBaseKey(baseHive, RegistryView.Registry64).OpenSubKey(PythonCorePath);
                    var res      = TryGetCPythonPath(version, python64, x64);
                    if (res != null)
                    {
                        return(res);
                    }
                }
            }

            var path = "C:\\Python" + version.ToString().Substring(1) + "\\python.exe";
            var arch = NativeMethods.GetBinaryType(path);

            if (arch == ProcessorArchitecture.X86 && !x64)
            {
                return(new PythonVersion(path, version, CPythonGuid));
            }
            else if (arch == ProcessorArchitecture.Amd64 && x64)
            {
                return(new PythonVersion(path, version, CPython64Guid));
            }

            if (x64)
            {
                path = "C:\\Python" + version.ToString().Substring(1) + "_x64\\python.exe";
                arch = NativeMethods.GetBinaryType(path);
                if (arch == ProcessorArchitecture.Amd64)
                {
                    return(new PythonVersion(path, version, CPython64Guid));
                }
            }

            return(null);
        }
예제 #3
0
        private static PythonVersion TryGetCPythonPath(PythonLanguageVersion version, RegistryKey python, bool x64)
        {
            if (python != null)
            {
                string versionStr = version.ToString().Substring(1);
                versionStr = versionStr[0] + "." + versionStr[1];
                if (!x64 && version >= PythonLanguageVersion.V35)
                {
                    versionStr += "-32";
                }

                using (var versionKey = python.OpenSubKey(versionStr + "\\InstallPath")) {
                    if (versionKey != null)
                    {
                        var installPath = versionKey.GetValue("");
                        if (installPath != null)
                        {
                            var path = Path.Combine(installPath.ToString(), "python.exe");
                            var arch = NativeMethods.GetBinaryType(path);
                            if (arch == ProcessorArchitecture.X86)
                            {
                                return(new PythonVersion(path, version, CPythonGuid));
                            }
                            else if (arch == ProcessorArchitecture.Amd64)
                            {
                                return(new PythonVersion(path, version, CPython64Guid));
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                }
            }
            return(null);
        }