diff --git a/easybuild/easyblocks/generic/pythonpackage.py b/easybuild/easyblocks/generic/pythonpackage.py index 38ca592328..f082e0474b 100644 --- a/easybuild/easyblocks/generic/pythonpackage.py +++ b/easybuild/easyblocks/generic/pythonpackage.py @@ -498,8 +498,6 @@ def prepare_python(self): python = os.path.join(python_root, 'bin', 'python') self.log.debug("Retaining 'python' command for Python dependency: %s", python) - req_py_majver = None - req_py_minver = None if python is None: # if no Python version requirements are specified, # use major/minor version of Python being used in this EasyBuild session @@ -513,19 +511,24 @@ 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: - 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 EasyConfigs " - "(req_py_majver = %s, req_py_minver = %s)", req_py_majver, req_py_minver - ) + # 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 EasyConfigs " + "(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: - raise EasyBuildError("Failed to pick Python command to use") + self.log.warning("No Python command found!") else: - self.log.warning("No Python command found!") + self.python_cmd = python + self.log.info("Python command being used: %s", self.python_cmd) + if self.python_cmd: # set Python lib directories