Wolfram Research

Function Repository Resource:

FindPythonExecutable (1.3.0) current version: 1.3.1 »

Source Notebook

Automatically attempt to find a Python executable on the current machine

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["FindPythonExecutable"][]

searches for a Python executable on the current machine and asks to install it with SystemInstall if not found.

ResourceFunction["FindPythonExecutable"][{"Python",opts}]

uses the options opts for the executable.

ResourceFunction["FindPythonExecutable"][assoc]

gets the executable specified by assoc.

ResourceFunction["FindPythonExecutable"][ExternalSessionObject[]]

gets the executable corresponding to the given "Python" session.

ResourceFunction["FindPythonExecutable"]["uuid"]

finds a Python executable for the external evaluator corresponding to the given UUID.

Details

In ResourceFunction["FindPythonExecutable"][assoc], elements of the association can be the same as in StartExternalSession.

Examples

Basic Examples

Find a Python executable on the current system:

In[1]:=
ResourceFunction["FindPythonExecutable"][]
Out[1]=

Get the executable corresponding to an association:

In[2]:=
ResourceFunction["FindPythonExecutable"][<|"Version" -> "3"|>]
Out[2]=

Use an ExternalSessionObject:

In[3]:=
session = StartExternalSession["Python"]
Out[3]=
In[4]:=
ResourceFunction["FindPythonExecutable"][session]
Out[4]=

Use a UUID:

In[5]:=
ResourceFunction["FindPythonExecutable", ResourceVersion->"1.3.0"]["e333f5ef-f448-4e27-ba47-6d9cbab96a28"]
Out[5]=

Validate a python executable path:

In[6]:=
ResourceFunction["FindPythonExecutable"]["/usr/bin/python2"]
Out[6]=
In[7]:=
ResourceFunction["FindPythonExecutable"]["python3"]
Out[7]=
In[8]:=
ResourceFunction["FindPythonExecutable"]["/usr/bin/notpython"]
Out[8]=
In[9]:=
ResourceFunction["FindPythonExecutable"]["/usr/bin/node"]
Out[9]=

Version History

  • 1.3.1 – 01 April 2022
  • 1.3.0 – 25 February 2022
  • 1.2.0 – 18 May 2021

Related Resources

Author Notes

Changelog

1.3.0 - 2022-02-12

Fixed
When searching FindExternalEvaluators for an executable, registered evaluators will be prioritized.
FindPythonExecutable[<||>] now behaves as documented by using StartExternalSession to resolve the specification.
Added
FindPythonExecutable["file"] will now find executables using the PATH environment variable.
Changed
Removed special behavior for FindPythonExecutable["Python"] since it's ambiguous with path specifications.

1.1.0 - 2021-01-29

Fixed
Fixed an issue with python executables not being found in 12.2 due to a change in FindExternalEvaluators.
Fixed an issue with python executables not being found when using a UUID corresponding to an external evaluator.
Changed
FindPythonExecutable now returns a Failure object instead of remaining unevaluated when there's an error.

License Information