JamSpell icon indicating copy to clipboard operation
JamSpell copied to clipboard

Runtime error on Ubuntu 16.04

Open kasteph opened this issue 6 years ago • 7 comments

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

kasteph avatar Apr 12 '18 16:04 kasteph

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.

bakwc avatar Apr 12 '18 16:04 bakwc

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

kasteph avatar Apr 13 '18 07:04 kasteph

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

ShaileshSridhar2403 avatar Feb 12 '21 12:02 ShaileshSridhar2403

All workarounds did not work for me. Used python:3.8 docker image as a base.

sibiryoff avatar Apr 28 '21 17:04 sibiryoff

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/*

romikforest avatar Jun 22 '21 00:06 romikforest

Using python:3.11-buster with @romikforest's solution worked for me. I could not it to work with standard python:3.11.

ziggycross avatar Jun 17 '23 22:06 ziggycross

thanks @romikforest worked for me with python 3.8 buster

marait123 avatar Nov 21 '23 12:11 marait123