The record I was addicted to when putting MeCab on Heroku

Purpose

I put pandas, plotly, and MeCab in flask, launched a simple web application on Heroku, and tried to enable simple morphological analysis and aggregation from anywhere.

I was addicted to deploying Heroku, so don't forget to record it.

environment

Windows10 Python3.7 Anaconda

What i did

Flask preparation omitted. No problem locally.

main.py test code (xlsx input, plotly output, html output part is deleted.)


# -*- coding: utf-8 -*-
import os
import csv
from flask import *
from werkzeug.utils import secure_filename
import pandas as pd
import plotly
import pathlib
import MeCab

app = Flask(__name__)

@app.route("/")
def init():
    cmd = "pip freeze"
    out = os.popen(cmd).read()
    return out

@app.route("/0")
def mecab():
    sentence = """Amazon Elastic Compute Cloud for AWS's Famous Services(EC2)And Amazon Simple Storage Service(S3)There is.
Compared to the physical server farms owned by clients so far, AWS has the advantage of being able to quickly provide large-scale computing power."""
    t = MeCab.Tagger('')
    out = t.parse(sentence)
    return out

if __name__ == '__main__':
    app.run()

requirements.txt


gunicorn==19.9.0
click==7.1.1
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
numpy==1.18.3
pandas==1.0.3
plotly==4.6.0
python-dateutil==2.8.1
pytz==2019.3
retrying==1.3.3
six==1.14.0
Werkzeug==1.0.1
xlrd==1.2.0
mecab-python3

Procfile


web: gunicorn main:app

.buildpacks


https://github.com/sunny4381/heroku-buildpack-linuxbrew.git

.cellar


mecab
mecab-ipadic
$ git init
$ heroku create flask-mecab-heroku
$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-multi
$ heroku config:add LD_LIBRARY_PATH=/app/.linuxbrew/lib
$ heroku config:set MECAB_PATH=/app/.linuxbrew/lib/libmecab.so
$ git add .
$ git commit -m "first"
$ git push heroku master

reference python + django + scikit-learn + mecab (1) on heroku https://qiita.com/kenchin110100/items/6f1c84ac8858525fffc5

problem

I can install mecab with Linuxbrew, but pip doesn't work. I can install packages with pip, but Linuxbrew doesn't work.

Solution

$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-multi Doesn't work. I had to set multiple buildpacks.

$ git init
$ heroku create flask-mecab-heroku2
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git
$ heroku buildpacks:add --index 2 heroku/python
$ heroku config:add LD_LIBRARY_PATH=/app/.linuxbrew/lib
$ heroku config:set MECAB_PATH=/app/.linuxbrew/lib/libmecab.so
$ git add .
$ git commit -m "first"
$ git push heroku master

output https://flask-mecab-heroku2.herokuapp.com/ https://flask-mecab-heroku2.herokuapp.com/0

Good grief. Now you can create an analysis page.

Looking back, it's a simple thing, but when you don't understand, you don't understand. Also, it seems that this is not the optimal solution ...

It would be nice to be able to create a web app around here, but heroku has only about 500MB of memory. https://qiita.com/kzuzuo/items/d41327433c9cdc6a5fd3 https://qiita.com/kzuzuo/items/8a80d8974bf3a7db7e54

Recommended Posts

The record I was addicted to when putting MeCab on Heroku
I was addicted to Flask on dotCloud
A note I was addicted to when making a beep on Linux
What I was addicted to when using Python tornado
I get [Error 2055] when trying to connect to MySQL on Heroku
What I was addicted to when migrating Processing users to Python
I was addicted to multiprocessing + psycopg2
Memo (March 2020) that I was addicted to when installing Arch Linux on MacBook Air 11'Early 2015
The story I was addicted to when I specified nil as a function argument in Go
What I was addicted to when introducing ALE to Vim for Python
A note I was addicted to when creating a table with SQLAlchemy
I was addicted to pip install mysqlclient
What I was addicted to Python autorun
Two things I was addicted to building Django + Apache + Nginx on Windows
When I tried to run Python, it was skipped to the Microsoft Store
I was addicted to running tensorflow on GPU with NVIDIA driver 440 + CUDA 10.2
A story I was addicted to when inserting from Python to a PostgreSQL table
A story I was addicted to trying to install LightFM on Amazon Linux
I was addicted to not being able to use Markdown on pypi's long_description
The file name was bad in Python and I was addicted to import
[Introduction to json] No, I was addicted to it. .. .. ♬
Log when I was worried that I could not connect to Wi-Fi on Linux
I stumbled on the character code when converting CSV to JSON in Python
I tried to use Resultoon on Mac + AVT-C875, but I was frustrated on the way.
Three things I was addicted to when using Python and MySQL with Docker
AtCoder AGC 041 C --I was addicted to the full search of Domino Quality
Summary of points I was addicted to running Selenium on AWS Lambda (python)
A note I was addicted to when running Python with Visual Studio Code
A story that I was addicted to when I made SFTP communication with python
I want to be notified when the command operation is completed on linux!
Record addicted to Basemap
Note that I was addicted to npm script not passing in the verification environment
I tried to make the phone ring when it was posted at the IoT post
When I tried to do socket communication with Raspberry Pi, the protocol was different
I tried python on heroku for the first time
I was addicted to scraping with Selenium (+ Python) in 2020
It was a life I wanted to OCR on AWS Lambda to locate the characters.
What I was addicted to when combining class inheritance and Joint Table Inheritance in SQLAlchemy
When I try to import pandas on macOS I get the error No module named'_bz2'
What I did when I was angry to put it in with the enable-shared option
When I deployed the Django app to Heroku, I got Module Not Found: <project-name> .wsgi.
A story that I was addicted to at np.where
The story when I was using IntelliJ on Linux and could not input Japanese
I was addicted to trying logging.getLogger in Flask 1.1.x
I tried to notify the honeypot report on LINE
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
What I was addicted to when dealing with huge files in a Linux 32bit environment
When I tried to install Ubuntu 18.04, "Initramfs unpacking failed: Decoding failed" was displayed and the startup failed.
[IOS] GIF animation with Pythonista3. I was addicted to it.
When I try to push with heroku, it doesn't work
How to deploy the easiest python textbook pybot on Heroku
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried to launch ipython cluster to the minimum on AWS
(Note) Points to be addicted to when installing Scilab on ArchLinux
[Fixed] I was addicted to alphanumeric judgment of Python strings
What I was addicted to when I built my own neural network using the weights and biases I got with scikit-learn's MLP Classifier.
The story of when I was addicted to Caused by SSLError ("Can't connect to HTTPS URL because the SSL module is not available.")
I got an error when I tried to process luigi in parallel on windows, but the solution
I wrote AWS Lambda, and I was a little addicted to the default value of Python arguments
Note that I was addicted to accessing the DB with Python's mysql.connector using a web application.
When I put Django in my home directory, I was addicted to static files with permission errors