Description
Hi Chris,
Many thanks for your excellent library which is changing the Clojure landscape.
I recently had an issue with autodetection of :python-home
in a virtual environment (built with either Poetry or venv) and solved it by (1) activating the virtual environment, (2) setting $PYTHONHOME
, and (3) calling lein $TASK
while inside the virtual environment.
Out of curiosity, I dug in further, and it seems to me that it may be more correct (at least to cover the use case of virtual environments) to autodetect :python-home
from sys.base_prefix
instead of the current sys.prefix
as used in the library function find-python-home
.
My reasoning:
PEP 405 -- Python Virtual Environments specifies that for virtual environments, sys.prefix
is changed to point relative to site-packages, while sys.base_prefix
is set relative to the Python executable and the standard libraries.
In addition, this is also is also emphasized in the documentation for the sys
module which states that when virtual environments are used, it is sys.base_prefix
that remains pointing to the base Python installation (the one which the virtual environment was created from).
I tried the patched version of find-python-home
below on my local machine with virtual environments (created by either Poetry or venv) and the autodetection of :python-home
works properly.
(defn find-python-home
[system-info & [{:keys [python-home]}]]
(cond
python-home
python-home
(seq (System/getenv "PYTHONHOME"))
(System/getenv "PYTHONHOME")
:else
(:base-prefix system-info))) ; change :prefix to :base-prefix
For your kind consideration. Many thanks!