OpenMS
PythonInfo Class Reference

Detect Python and retrieve information. More...

#include <OpenMS/SYSTEM/PythonInfo.h>

Static Public Member Functions

static bool canRun (String &python_executable, String &error_msg)
 Determine if Python is installed and executable. More...
 
static bool isPackageInstalled (const String &python_executable, const String &package_name)
 Determine if the Python given in python_executable has the package package_name already installed. More...
 
static String getVersion (const String &python_executable)
 Determine the version of Python given in python_executable by calling '–version'. More...
 

Detailed Description

Detect Python and retrieve information.

Similar classes exist for other external tools, e.g. JavaInfo .

Member Function Documentation

◆ canRun()

static bool canRun ( String python_executable,
String error_msg 
)
static

Determine if Python is installed and executable.

The call fails if either Python is not installed or if a relative location is given and Python is not on the search PATH. If Python is found, the executable name will be modified to the absolute path. If Python is not found, an error message will be put into error_msg

Parameters
python_executablePath to Python executable. Can be absolute, relative or just a filename
error_msgOn error, contains detailed error description (e.g.
Returns
Returns false if Python executable can not be called; true if Python executable can be executed

◆ getVersion()

static String getVersion ( const String python_executable)
static

Determine the version of Python given in python_executable by calling '–version'.

If Python cannot be found, the function will return the empty string. Thus, make sure that PythonInfo::canRun() succeeds before calling this function.

Parameters
python_executableAs determined by canRun()...
Returns
the output of 'python –version'

◆ isPackageInstalled()

static bool isPackageInstalled ( const String python_executable,
const String package_name 
)
static

Determine if the Python given in python_executable has the package package_name already installed.

If Python cannot be found, the function will just return false. Thus, make sure that PythonInfo::canRun() succeeds before calling this function.

Parameters
python_executableAs determined by canRun()...
package_nameThe package you want to test (mind lower/upper case!)
Returns
true if package is installed