Search code examples
pythonpython-3.xdockerhunspell

Cannot open shared object file when using docker


When I run the program following script:

from hunspell import Hunspell

if __name__ == '__main__':
    h = Hunspell()
    print(h.spell('test'))

On local machine everything is OK but when as soon as I build and run the code on docker, it throws following exception:

    from hunspell import Hunspell
  File "/usr/local/lib/python3.6/site-packages/hunspell/__init__.py", line 3, in <module>
    from .hunspell import HunspellWrap as Hunspell
ImportError: libhunspell-1.3.so.0: cannot open shared object file: No such file or directory

My Dockerfile is something like:

FROM python:3

ADD main.py /

RUN pip install cyhunspell

CMD [ "python", "main.py" ]

Hunspell use c++ binary files that I think causing such exception.

Does anybody know how to fix this issue? Is it necessary to use Linux for base image in Dockerfile?


Solution

  • Install the missing packages:

    FROM python:3
    
    ADD main.py /
    RUN apt-get update
    RUN apt-get install -y libhunspell-1.3-0
    RUN pip install cyhunspell
    
    CMD [ "python", "main.py" ]