How to use python scikit-learn + mecab on heroku.
heroku has heroku-buildpack-mecab for handling mecab in Ruby, but not for python. So use heroku-buildpack-linuxbrew to brew install mecab.
Also, heroku-buildpack-python cannot install libraries that require a c compiler, such as scipy and scikit-learn. Instead, install miniconda instead of python with heroku-buildpack-conda to install these packages.
In order to handle these multiple buildpacks, you need to create an app with heroku-buildpack-multi.
First in the local repository for heroku
$ git init
$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-multi
Create an app with.
Then create .buildpacks in your local repository
.buildpacks
https://github.com/kennethreitz/conda-buildpack.git
https://github.com/sunny4381/heroku-buildpack-linuxbrew.git
Write and save. buildpack-multi will install the buildpack listed in this file.
Create a .cellar in the same directory
.cellar
mecab
mecab-ipadic
Write and save. buildpack-linuxbrew will install the applications listed in this file.
The libraries you want to install with pip and conda are If you describe it in requirements.txt and conda-requirements.txt, it will be installed without permission.
$ pip freeze > requirements.txt
Or
$ conda list > requirements.txt
** Note that mecab-python cannot be installed with pip ** (maybe I should increase the version of pip ??)
sh: 1: mecab-config:I get a not found error
So mecab-python is installed manually on heroku (quite brute force ...)
In preparation for that, in the local repository
```shell-session
$ curl -O https://mecab.googlecode.com/files/mecab-python-0.996.tar.gz
$ tar zxfv mecab-python-0.996.tar.gz
$ rm https://mecab.googlecode.com/files/mecab-python-0.996.tar.gz
Extract mecab-python.
Also change 'mecab-config'
in setpu.py in mecab-python-0.996 to `` `'/app/.linuxbrew/bin/mecab-config'```. (Reference source: http://qiita.com/saicologic/items/ab70e14f7e2ec2ee0b4d)
After all these things are done, deploy with bash.
$ heroku config:add LD_LIBRARY_PATH=/app/.linuxbrew/lib
$ heroku config:set MECAB_PATH=/app/.linuxbrew/lib/libmecab.so
$ git add .
$ git commit -m 'initial'
$ git push heroku master
After deploying, manually install mecab-python on heroku.
$ heroku run bash
~/ cd mecab-python-0.996
~/ python setup.py build
~/ python setup.py install
OK ... Finally, start python on heroku and check if import MeCab can be done.
Now you can use python + scikit-learn + mecab on heroku, but the file size is messed up ...
I feel that the free 300M is pretty tough ... (Reference source: http://qiita.com/shouta-dev/items/cd538a77f2b729333025)
Recommended Posts