7

I tried to deploy my flask application in a docker in ubuntu18.04, and I was using python3.5 in my pipenv. But when I run docker build -t flask ., at a step of RUN pipenv install,I got this error:

RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/en/7.x/python3/ for mitigation steps.

This system supports the C.UTF-8 locale which is recommended.
You might be able to resolve your issue by exporting the
following environment variables:

    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8

But when I checked my locale with locale,it returned

LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=C.UTF-8

I guessed maybe something was different in docker so I tried to add

RUN export LC_ALL=C.UTF-8
RUN export LANG=C.UTF-8

into my Dockerfile, but still got this error.

I'm shriveled. Since I had set all to C.utf-8, I have no idea why it's still complaining. I had searched this problem online but unfortunately all the methods seemed to be useless in my case :( Maybe there are some tiny things I have been ignoring, but I really cannot figure them out. I hope someone could help me out and save me another 3 hours.Thanks.

bohnsix
  • 111
  • 2
  • 4
  • 3
    A `RUN export foo=bar` will have no effect, as it won't carry over into subsequent lines or the command that is executed for the container. You need to do `ENV foo bar` in the Dockerfile. See https://stackoverflow.com/a/28406007/794539 – blubberdiblub Aug 26 '19 at 06:30
  • What was the solution? – ThomasATU Sep 01 '20 at 21:24
  • FYI for those wondering why this error happens read about the issue here [PEP 538](https://www.python.org/dev/peps/pep-0538/) and [PEP 540](https://www.python.org/dev/peps/pep-0540/)the issue is related to operating system `locales` and seems to only be an issue for python 3.0 to 3.6 and is python >= 3.7 fixed the issue. – Trevor Boyd Smith Oct 18 '21 at 12:45
  • Does this answer your question? [Encoding issue with python3 and click package](https://stackoverflow.com/questions/32234393/encoding-issue-with-python3-and-click-package) – Trevor Boyd Smith Oct 18 '21 at 15:25

4 Answers4

4

RUN will just run command in layer while building it. set this env variable ENV export LC_ALL=C.UTF-8 ENV export LANG=C.UTF-8

Aftab
  • 41
  • 2
0

export LC_ALL=en_US.utf-8 && export LANG=en_US.utf-8

cafebabe
  • 33
  • 2
0

I had same error with the celery as well... this is how I solved:

celery:
    ...
    environment:
      - LC_ALL=C.UTF-8
      - LANG=C.UTF-8
    ...
smit
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 24 '22 at 04:10
-1

Modify docker file:

Add export LC_ALL=C.UTF-8 && export LANG=C.UTF-8 command along with python command like follows

RUN export LC_ALL=C.UTF-8  && export LANG=C.UTF-8 && python3.6 -m spacy download en_core_web_sm
Ramesh Ponnusamy
  • 1,553
  • 11
  • 22