Deploy matplotlib on heroku failed. How to do this correctly?

heroku, matplotlib, python, python-2.7

Solution

Finally I'm able to manage this.

First of all, I use this buildpack: https://github.com/dbrgn/heroku-buildpack-python-sklearn To use this buildpack I run this (maybe it is not a necessary step):

heroku config:set BUILDPACK_URL=https://github.com/dbrgn/heroku-buildpack-python-sklearn/

Then I change the requirements.txt into this:

argparse==1.2.1
distribute==0.6.24
gunicorn==17.5
wsgiref==0.1.2
numpy==1.7.0
matplotlib==1.1.0
scipy==0.11.0
scikit-learn==0.13.1

The most important part here is I install matplotlib 1.1.0 (currently the newest is 1.3.0). Some "deprecated numpy API" warnings might be occurred. But in my case it seems to be alright.

And here is the result (the page site might probably down since I use the free server one) http://kokoropy.herokuapp.com/example/plotting

Problem

I've install matplotlib in my virtualenv using pip. It was a failure at the beginning, but after I do `easy_install -U distribute`, the installation goes smoothly. Here is what I do (inside my git repository root folder): ``` virtualenv env source env/bin/activate pip install gunicorn pip install numpy easy_install -U distribute pip install matplotlib ``` Then, I make a requirements.txt by using `pip freeze > requirements.txt`. Here is the result: ``` argparse==1.2.1 distribute==0.7.3 gunicorn==17.5 matplotlib==1.3.0 nose==1.3.0 numpy==1.7.1 pyparsing==2.0.1 python-dateutil==2.1 six==1.3.0 tornado==3.1 wsgiref==0.1.2 ``` Problem happened when I try to deploy my application: ``` (env)gofrendi@kirinThor:~/kokoropy$ git push -u heroku Counting objects: 9, done. Delta compression using up to 2 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 586 bytes, done. Total 5 (delta 3), reused 0 (delta 0) -----> Python app detected -----> No runtime.txt provided; assuming python-2.7.4. -----> Using Python runtime (python-2.7.4) -----> Installing dependencies using Pip (1.3.1) Downloading/unpacking distribute==0.7.3 (from -r requirements.txt (line 2)) Running setup.py egg_info for package distribute Downloading/unpacking matplotlib==1.3.0 (from -r requirements.txt (line 4)) Running setup.py egg_info for package matplotlib The required version of distribute (>=0.6.28) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U distribute'. (Currently using distribute 0.6.24 (/app/.heroku/python/lib/python2.7/site-packages)) Complete output from command python setup.py egg_info: The required version of distribute (>=0.6.28) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U distribute'. (Currently using distribute 0.6.24 (/app/.heroku/python/lib/python2.7/site-packages)) ---------------------------------------- Command python setup.py egg_info failed with error code 2 in /tmp/pip-build-u55833/matplotlib Storing complete log in /app/.pip/pip.log ! Push rejected, failed to compile Python app To git@heroku.com:kokoropy.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@heroku.com:kokoropy.git' (env)gofrendi@kirinThor:~/kokoropy$ ``` Seems that heroku server can't install matplotlib correctly. When I do `easy_install -U distribute` it might not being recorded by pip. Matplotlib also has several non-python-library dependencies (such as: libjpeg8-dev, libfreetype and libpng6-dev). I can install those dependencies locally (e.g: via `apt-get`). However, this also not being recorded by pip. So, my question is: how to correctly install matplotlib in heroku deployment server?

Original source