convex_heroku_transparent

In a recent project, I needed to setup a web server that could solve quadratic programs via a simple API. Conveniently, as of January 15th, 2015, CVXOPT is included in the list of packages that can be installed using conda (Linux and Mac only). Thanks to the conda buildpack for Heroku created by Kenneth Reitz, the process of adding CVXOPT to a Python app is fairly simple. You can follow this same procedure to add popular scientific python packages (like numpy, scipy, scikit-learn, statsmodels, and pandas) to a Heroku app.

I. Buildpack

1.0 New Apps

If you are starting a new Python app on Heroku, you can add the conda buildpack using the command:

$ heroku create YOUR_APP_NAME --buildpack https://github.com/kennethreitz/conda-buildpack.git

1.1 Existing Apps

If you have already setup a Python app on Heroku, you can add the conda buildpack to the existing app using the command:

$ heroku config:add BUILDPACK_URL=https://github.com/kennethreitz/conda-buildpack.git

Or, if you need to specify the app by name:

$ heroku config:add BUILDPACK_URL=https://github.com/kennethreitz/conda-buildpack.git --app YOUR_APP_NAME

II. Use

2.1 Requirements

To use the buildpack, you will need to include two text files in the app directory, requirements.txt and conda-requirements.txt. Just as with the standard Python buildpack, the requirements.txt file lists packages that should be installed using pip. Packages that should be installed using conda are listed in the conda-requirements.txt file. Some of the most useful scientific packages include cvxoptnumpy, scipy, scikit-learn, statsmodels, and pandas. The full list of available conda packages can be found at repo.continuum.io

For example:

$ cat requirements.txt

gunicorn==0.14.2

requests==0.11.1

$ cat conda-requirements.txt
scipy

numpy
cvxopt

That’s it! You can now add CVXOPT to a Python app on Heroku. 

2.2 With ATLAS

CVXOPT recommends using ATLAS libraries for a performance improvement over standard BLAS & LAPACK libraries. If you want to use CVXOPT with ATLAS instead of BLAS & LAPACK , I have forked Mr. Reitz’s repository and modified the conda buildpack to accept a custom-requirements.txt file. The file lists packages that should be installed using a customized installation procedure. Currently, only cvxopt-atlas is supported.

To use my forked conda buildpack (fair warning, the repository may not have the most recent version of conda):

$ heroku config:add BUILDPACK_URL=https://github.com/ericburger/conda-buildpack.git

Include the custom-requirements.txt file in the app directory:

$ cat custom-requirements.txt
cvxopt-atlas

The cvxopt-atlas install procedure will use the atlas library available through conda

 

I hope this short tutorial will save someone from a few hours of frustration!

 

2 Comments

  1. Peter
    November 20, 2015

    Nice work! Thanks for this tutorial. I’ve been trying to get sklearn working on Heroku for way to long. This was the only build pack I got to work.

    Reply
  2. rigoxls
    December 16, 2015

    Yes i agree , i tried 2 buildpacks before using this without success, this one is the only one who works without bugs, warnings, errors…

    thanks… good post

    Reply

Leave a Reply