How to get the path to Python 3 requirement when writing a formula with Python bindings

(Tom Close) #1

I am trying to add the option to install using Python 3 bindings to the Neuron formula,

I can get it to work by forcing the use of Homebrew’s Python 3

depends_on "python3" => :optional

if build.with? "python3"
    args << "--with-nrnpython=#{Formula["python3"].opt_prefix}/bin/python3"
    args << "--with-nrnpython"

but the docs say that I should use the requirement :python3 instead of the Homebrew dependency “python3”, to allow the build to pick up an alternative Python 3 installation on the system path.

So my question is, how do I get the path to the Python 3 executable from the :python requirement?

(Tom Close) #2

Nevermind, I’m not quite sure what I tried previously but just providing “python3” to the nrnpython flag seems to do the trick.

I was also thinking that it should be possible to get the Python installation details from something like

py_prefix = `python3 -c "import sysconfig; print(sysconfig.get_config_var('prefix'));"`