Skip to content

Commit

Permalink
Add option to set Python interpreter path
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Dec 31, 2023
1 parent 3010293 commit 3304d23
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3304d23

Please sign in to comment.