From 3304d23f4bc9651f7cffefbf0638de4167c99e20 Mon Sep 17 00:00:00 2001 From: xxyzz Date: Sun, 31 Dec 2023 20:09:56 +0800 Subject: [PATCH] Add option to set Python interpreter path --- config.py | 13 +++++++++++++ deps.py | 6 +++++- utils.py | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 0352a99..a41e899 100644 --- a/config.py +++ b/config.py @@ -66,6 +66,7 @@ prefs.defaults["last_opened_kindle_lemmas_language"] = "ca" prefs.defaults["last_opened_wiktionary_lemmas_language"] = "ca" prefs.defaults["use_wiktionary_for_kindle"] = False +prefs.defaults["python_path"] = "" for code in load_plugin_json(get_plugin_path(), "data/languages.json").keys(): prefs.defaults[f"{code}_wiktionary_difficulty_limit"] = 5 @@ -119,6 +120,17 @@ def __init__(self): QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow ) + python_path_label = QLabel(_("Python path")) + python_path_label.setToolTip( + _( + "Absolute path of the executable binary for the Python interpreter, " + "leave this empty to find Python in PATH." + ) + ) + self.python_path = QLineEdit() + self.python_path.setText(prefs["python_path"]) + form_layout.addRow(python_path_label, self.python_path) + if not ismacos: self.use_gpu_box = QCheckBox(_("Run spaCy with GPU(requires CUDA)")) self.use_gpu_box.setToolTip( @@ -217,6 +229,7 @@ def open_github(self) -> None: webbrowser.open(GITHUB_URL) def save_settings(self) -> None: + prefs["python_path"] = self.python_path.text() prefs["use_pos"] = self.use_pos_box.isChecked() prefs["search_people"] = self.search_people_box.isChecked() prefs["model_size"] = self.model_size_box.currentData() diff --git a/deps.py b/deps.py index ddf4d69..fc3e859 100644 --- a/deps.py +++ b/deps.py @@ -83,8 +83,12 @@ def which_python() -> tuple[str, str]: """ Return Python command or file path and version string """ + from .config import prefs + py = "python3" - if iswindows: + if len(prefs["python_path"]) > 0: + py = prefs["python_path"] + elif iswindows: py = "py" if shutil.which("py") else "python" elif ismacos: py = mac_bin_path("python3") diff --git a/utils.py b/utils.py index be33337..6825a25 100644 --- a/utils.py +++ b/utils.py @@ -38,6 +38,7 @@ class Prefs(TypedDict): last_opened_kindle_lemmas_language: str last_opened_wiktionary_lemmas_language: str use_wiktionary_for_kindle: bool + python_path: str def load_plugin_json(plugin_path: Path, filepath: str) -> Any: