diff --git a/easybuild/easyblocks/generic/pythonbundle.py b/easybuild/easyblocks/generic/pythonbundle.py index 01d9c4c672..73df0fd3a7 100644 --- a/easybuild/easyblocks/generic/pythonbundle.py +++ b/easybuild/easyblocks/generic/pythonbundle.py @@ -109,6 +109,15 @@ def prepare_step(self, *args, **kwargs): python_cmd = pick_python_cmd(req_maj_ver=req_py_majver, req_min_ver=req_py_minver) + # If pick_python_cmd didn't find a (system) Python command, we should raise an error + if python_cmd: + self.log.info("Python command being used: %s", python_cmd) + else: + raise EasyBuildError( + "Failed to pick Python command that satisfies requirements in the easyconfig " + "(req_py_majver = %s, req_py_minver = %s)", req_py_majver, req_py_minver + ) + self.all_pylibdirs = get_pylibdirs(python_cmd=python_cmd) self.pylibdir = self.all_pylibdirs[0] diff --git a/easybuild/easyblocks/generic/pythonpackage.py b/easybuild/easyblocks/generic/pythonpackage.py index f2ae208ebc..5ab60c6077 100644 --- a/easybuild/easyblocks/generic/pythonpackage.py +++ b/easybuild/easyblocks/generic/pythonpackage.py @@ -511,13 +511,23 @@ def prepare_python(self): # if using system Python, go hunting for a 'python' command that satisfies the requirements python = pick_python_cmd(req_maj_ver=req_py_majver, req_min_ver=req_py_minver) - if python: + # Check if we have Python by now. If not, and if self.require_python, raise a sensible error + if python: + self.python_cmd = python + self.log.info("Python command being used: %s", self.python_cmd) + elif self.require_python: + if req_py_majver is not None or req_py_minver is not None: + raise EasyBuildError( + "Failed to pick Python command that satisfies requirements in the easyconfig " + "(req_py_majver = %s, req_py_minver = %s)", req_py_majver, req_py_minver + ) + else: + raise EasyBuildError("Failed to pick Python command to use") + else: + self.log.warning("No Python command found!") + else: self.python_cmd = python self.log.info("Python command being used: %s", self.python_cmd) - elif self.require_python: - raise EasyBuildError("Failed to pick Python command to use") - else: - self.log.warning("No Python command found!") if self.python_cmd: # set Python lib directories