JamSpell
JamSpell copied to clipboard
Runtime error on Ubuntu 16.04
I am using the Python bindings for Jamspell. Assuming that I have the following Dockerfile:
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:jonathonf/python-3.6
RUN apt-get update
RUN apt install -y build-essential libstdc++6 wget git swig libssl-dev python3.6 python3.6-dev python3-pip python3.6-venv
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
RUN python3.6 -m pip install pip --upgrade
RUN python3.6 -m pip install wheel
COPY . /app
WORKDIR /app
RUN python3.6 -m pip install -r requirements.txt
CMD ["python3.6", "-m", "http.server"]
I get the following error on import jamspell
:
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
The locales are set with the ENV
directives and when checking the locales with locale
on interactive terminal in Docker, LANG
and LC_ALL
are set. Is there anything that I'm missing with my dependencies?
Cheers, steph
Thanks for report! Currently I'm setting locale "en_US.UTF-8" and ignore system locale. Apparently this is wrong, I'll try to fix, meanwhile you can try to install "en_US.UTF-8" locale to your system.
Thanks @bakwc! For anyone else running into this issue:
apt-get install locales
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
... worked for me using command line args. BUT you may still run into an issue:
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module> sys.exit(pip.main())
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main locale.setlocale(locale.LC_ALL, '')
File "/usr/lib/python3.6/locale.py", line 598, in setlocale return _setlocale(category, locale)
locale.Error: unsupported locale setting
The working Dockerfile has the following:
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8
attribution: https://serverfault.com/questions/362903/how-do-you-set-a-locale-non-interactively-on-debian-ubuntu
Needed to add
RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment && \
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \
echo "LANG=en_US.UTF-8" > /etc/locale.conf && \
locale-gen en_US.UTF-8
To get it to work
All workarounds did not work for me. Used python:3.8
docker image as a base.
I used for python:3.9.5-buster docker container (Debian based, not ubuntu):
RUN set -e ; \
apt-get update -y ; \
DEBIAN_FRONTEND=noninteractive apt-get install -y locales ;\
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen ; \
locale-gen ; \
DEBIAN_FRONTEND=noninteractive apt-get install -y swig3.0 ; \
apt-get clean ; \
rm -rf /var/lib/apt/lists/*
Using python:3.11-buster
with @romikforest's solution worked for me. I could not it to work with standard python:3.11
.
thanks @romikforest worked for me with python 3.8 buster