Had the same problem and @Epistemex'slink helped me troubleshoot it.

... You need to installlibcairo2-dev, libjpeg-dev and libgif-dev packages ...

sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev