diff --git a/admin/settings/server.php b/admin/settings/server.php index 32af104484e..e84707740f6 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -12,6 +12,8 @@ $temp->add(new admin_setting_configexecutable('pathtodu', new lang_string('patht $temp->add(new admin_setting_configexecutable('aspellpath', new lang_string('aspellpath', 'admin'), new lang_string('edhelpaspellpath'), '')); $temp->add(new admin_setting_configexecutable('pathtodot', new lang_string('pathtodot', 'admin'), new lang_string('pathtodot_help', 'admin'), '')); $temp->add(new admin_setting_configexecutable('pathtogs', new lang_string('pathtogs', 'admin'), new lang_string('pathtogs_help', 'admin'), '/usr/bin/gs')); +$temp->add(new admin_setting_configexecutable('pathtopython', new lang_string('pathtopython', 'admin'), + new lang_string('pathtopythondesc', 'admin'), '')); $ADMIN->add('server', $temp); diff --git a/lang/en/admin.php b/lang/en/admin.php index dc905816d67..f2ad60bc7a0 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -835,6 +835,8 @@ $string['pathtopgdumpinvalid'] = 'Invalid path to pg_dump - either wrong path or $string['pathtopsql'] = 'Path to psql'; $string['pathtopsqldesc'] = 'This is only necessary to enter if you have more than one psql on your system (for example if you have more than one version of postgresql installed)'; $string['pathtopsqlinvalid'] = 'Invalid path to psql - either wrong path or not executable'; +$string['pathtopython'] = 'Path to Python'; +$string['pathtopythondesc'] = 'Path to your executable Python binary.'; $string['pcreunicodewarning'] = 'It is strongly recommended to use PCRE PHP extension that is compatible with Unicode characters.'; $string['perfdebug'] = 'Performance info'; $string['performance'] = 'Performance'; diff --git a/lib/mlbackend/python/classes/processor.php b/lib/mlbackend/python/classes/processor.php index 84889e21235..faa9f6cf61b 100644 --- a/lib/mlbackend/python/classes/processor.php +++ b/lib/mlbackend/python/classes/processor.php @@ -40,15 +40,38 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso */ const REQUIRED_PIP_PACKAGE_VERSION = '0.0.2'; + /** + * The path to the Python bin. + * + * @var string + */ + protected $pathtopython; + + /** + * The constructor. + */ + public function __construct() { + global $CFG; + + // Set the python location if there is a value. + if (!empty($CFG->pathtopython)) { + $this->pathtopython = $CFG->pathtopython; + } + } + /** * Is the plugin ready to be used?. * - * @return bool + * @return bool|string Returns true on success, a string detailing the error otherwise */ public function is_ready() { + if (empty($this->pathtopython)) { + $settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths')); + return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out()); + } // Check the installed pip package version. - $cmd = 'python -m moodlemlbackend.version'; + $cmd = "{$this->pathtopython} -m moodlemlbackend.version"; $output = null; $exitcode = null; @@ -84,7 +107,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso // Obtain the physical route to the file. $datasetpath = $this->get_file_path($dataset); - $cmd = 'python -m moodlemlbackend.training ' . + $cmd = "{$this->pathtopython} -m moodlemlbackend.training " . escapeshellarg($uniqueid) . ' ' . escapeshellarg($outputdir) . ' ' . escapeshellarg($datasetpath); @@ -125,7 +148,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso // Obtain the physical route to the file. $datasetpath = $this->get_file_path($dataset); - $cmd = 'python -m moodlemlbackend.prediction ' . + $cmd = "{$this->pathtopython} -m moodlemlbackend.prediction " . escapeshellarg($uniqueid) . ' ' . escapeshellarg($outputdir) . ' ' . escapeshellarg($datasetpath); @@ -168,7 +191,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso // Obtain the physical route to the file. $datasetpath = $this->get_file_path($dataset); - $cmd = 'python -m moodlemlbackend.evaluation ' . + $cmd = "{$this->pathtopython} -m moodlemlbackend.evaluation " . escapeshellarg($uniqueid) . ' ' . escapeshellarg($outputdir) . ' ' . escapeshellarg($datasetpath) . ' ' . diff --git a/lib/mlbackend/python/lang/en/mlbackend_python.php b/lib/mlbackend/python/lang/en/mlbackend_python.php index fad23ba3383..a3baa85bea3 100644 --- a/lib/mlbackend/python/lang/en/mlbackend_python.php +++ b/lib/mlbackend/python/lang/en/mlbackend_python.php @@ -25,3 +25,4 @@ $string['packageinstalledshouldbe'] = '"moodlemlbackend" python package should be updated. The required version is "{$a->required}" and the installed version is "{$a->installed}"'; $string['pluginname'] = 'Python machine learning backend'; $string['pythonpackagenotinstalled'] = '"moodlemlbackend" python package is not installed or there is a problem with it. Please execute "{$a}" from command line interface for more info'; +$string['pythonpathnotdefined'] = 'The path to your executable Python binary has not been defined. Please visit "{$a}" to set it.';