'RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment

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.



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

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
    ...

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aftab
Solution 2 cafebabe
Solution 3 smit
Solution 4