FreeCAD

Форк
0
/
utils.py 
63 строки · 3.2 Кб
1
# SPDX-License-Identifier: LGPL-2.1-or-later
2
# ***************************************************************************
3
# *                                                                         *
4
# *   Copyright (c) 2022-2023 FreeCAD Project Association                   *
5
# *   Copyright (c) 2018 Gaël Écorchard <galou_breizh@yahoo.fr>             *
6
# *                                                                         *
7
# *   This file is part of FreeCAD.                                         *
8
# *                                                                         *
9
# *   FreeCAD is free software: you can redistribute it and/or modify it    *
10
# *   under the terms of the GNU Lesser General Public License as           *
11
# *   published by the Free Software Foundation, either version 2.1 of the  *
12
# *   License, or (at your option) any later version.                       *
13
# *                                                                         *
14
# *   FreeCAD is distributed in the hope that it will be useful, but        *
15
# *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
16
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
17
# *   Lesser General Public License for more details.                       *
18
# *                                                                         *
19
# *   You should have received a copy of the GNU Lesser General Public      *
20
# *   License along with FreeCAD. If not, see                               *
21
# *   <https://www.gnu.org/licenses/>.                                      *
22
# *                                                                         *
23
# ***************************************************************************
24

25
import os
26
import platform
27
import shutil
28

29
import FreeCAD
30

31

32
def get_python_exe() -> str:
33
    """Find Python. In preference order
34
    A) The value of the PythonExecutableForPip user preference
35
    B) The executable located in the same bin directory as FreeCAD and called "python3"
36
    C) The executable located in the same bin directory as FreeCAD and called "python"
37
    D) The result of a shutil search for your system's "python3" executable
38
    E) The result of a shutil search for your system's "python" executable"""
39
    prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/PythonConsole")
40
    python_exe = prefs.GetString("ExternalPythonExecutable", "Not set")
41
    fc_dir = FreeCAD.getHomePath()
42
    if not python_exe or python_exe == "Not set" or not os.path.exists(python_exe):
43
        python_exe = os.path.join(fc_dir, "bin", "python3")
44
        if "Windows" in platform.system():
45
            python_exe += ".exe"
46

47
    if not python_exe or not os.path.exists(python_exe):
48
        python_exe = os.path.join(fc_dir, "bin", "python")
49
        if "Windows" in platform.system():
50
            python_exe += ".exe"
51

52
    if not python_exe or not os.path.exists(python_exe):
53
        python_exe = shutil.which("python3")
54

55
    if not python_exe or not os.path.exists(python_exe):
56
        python_exe = shutil.which("python")
57

58
    if not python_exe or not os.path.exists(python_exe):
59
        return ""
60

61
    python_exe = python_exe.replace("/", os.path.sep)
62
    prefs.SetString("ExternalPythonExecutable", python_exe)
63
    return python_exe
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.