'How to install PyEnchant on Heroku?

It seems that PyEnchant requires the C enchant library. How would I go about installing this on Heroku, is that possible?

According to this question, I would need to write my own build pack for Heroku, so I guess that's one way. But I'm hoping there is a simpler technique to use?



Solution 1:[1]

For these kind of things we are using heroku-buildpack-apt, which let's you install any package.

Solution 2:[2]

Acording to the answer of Denis Cornehl I add an Aptfile to the project with this content:

libenchant-dev

And that removed the error of the C library.

However in my case I can't find a way of add a spanish dictionary, I tried add myspell-es in the same Aptfile, but without success.

UPDATE: Since I was having problems with the spanish dictionary. I stopped trying to deploy that way and I use a Dockerfile. This way I have more control of which OS libraries install. With this Dockerfile I was able to use pyenchant with a spanish dictionary (By the way, my app uses Flask, for that the CMD command uses gunicorn):

FROM python:3.8-slim-buster

WORKDIR /

RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install libenchant-dev hunspell hunspell-es

COPY requirements.txt .
COPY app.py .

RUN pip install -r requirements.txt

CMD gunicorn --bind 0.0.0.0:$PORT app:app

And the way to deploy it is slightly different:

heroku login
heroku create <your_app_name>
heroku container:login
heroku container:push web --app <your_app_name>
heroku container:release web --app <your_app_name>

I hope this helps you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Denis Cornehl
Solution 2