python + django + scikit-learn + mecab (1) on heroku

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

python + django + scikit-learn + mecab (1) on heroku
python + django + scikit-learn + mecab (2) on heroku
Notes on using MeCab from Python
Don't lose to Ruby! How to run Python (Django) on Heroku
Deploy your Django application on Heroku
Publish DJango page on heroku: Practice
Mecab / Cabocha / KNP on Python + Windows
Python json.loads () returns str on Heroku
Django blog on heroku: login implementation
Periodically run Python on Heroku Scheduler
Migrate Django applications running on Python 2.7 to Python 3.5
Deploy Django api on heroku (personal note)
Deploy the Django app on Heroku [Part 2]
Deploy the Django app on Heroku [Part 1]
Django Heroku Deploy 1
Redis on Heroku
Python on Windows
Python Django Tutorial (5)
twitter on python3
shimehari on heroku
Python Django Tutorial (8)
Python Django Tutorial (6)
python on mac
LINE heroku python
MeCab from Python
Django Heroku Deploy 2
Python on Windbg
Python Django Tutorial (7)
Python Django Tutorial (1)
Python Django tutorial tutorial
Python Django Tutorial (3)
Python Django Tutorial (4)
How to run MeCab on Ubuntu 18.04 LTS Python
A story about running Python on PHP on Heroku
A memorandum for touching python Flask on heroku
What Python beginners got hooked on with Django
Until you use PhantomJS with Python on Heroku
Install mecab on Marvericks
Django 1.11 started with Python3.6
Deploy a Python 3.6 / Django / Postgres web app on Azure
Python conda on cygwin
Install python on WSL
Python Django tutorial summary
Django python web framework
PyOpenGL setup on Python 3
heroku deployment memo (Django)
Scraping with Python, posting on TwitterBot, regular execution on Heroku
Install Scrapy on python3
[Heroku] Memo for deploying Python apps using Heroku on Windows [Python]
Celery notes on Django
Run Django on PythonAnywhere
Django Python shift table
Use mecab with Python3
Install Python on Mac
Install Python 3 on Mac
I tried python on heroku for the first time
Install Python3.4 on CentOS 6.6
Deploy a Django application on Google App Engine (Python3)
How to build a Django (python) environment on docker
Try Debian + Python 3.4 + django1.7 ...
Installing pandas on python2.6