Wolfram Research

Function Repository Resource:

FindPythonExecutable

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 (5) 

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"]["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]=

Resource History

Related Resources

Author Notes

Changelog

1.3.1 - 2022-03-20

Fixed
FindPythonExecutable now works correctly with macOS virtual environments, and particularly with CreatePythonVirtualEnvironment.

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