Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error on Ubuntu 16.04 #17

Open
kasteph opened this issue Apr 12, 2018 · 7 comments
Open

Runtime error on Ubuntu 16.04 #17

kasteph opened this issue Apr 12, 2018 · 7 comments
Labels

Comments

@kasteph
Copy link

kasteph commented Apr 12, 2018

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

@bakwc
Copy link
Owner

bakwc commented Apr 12, 2018

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 bakwc added the bug label Apr 12, 2018
@kasteph
Copy link
Author

kasteph commented Apr 13, 2018

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

@ShaileshSridhar2403
Copy link

ShaileshSridhar2403 commented Feb 12, 2021

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

@sibiryoff
Copy link

sibiryoff commented Apr 28, 2021

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

@romikforest
Copy link

romikforest commented Jun 22, 2021

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

@ziggycross
Copy link

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

@marait123
Copy link

thanks @romikforest worked for me with python 3.8 buster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants