I was trying to install magento 2 locally after cloning the project from its github’s repository, but I was confronted with this error.
Even, it was hard to tell for normal user what caused the error. After looking at logs, I came to conclusion that, the var/ and pub/ directories in the root directory need to be php writable. Hence I changed their permission to 777, and it worked!