Redeem Now
Read More
Read now
Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Set the locale to UTF-8 for Python 3

    I had been struggling while installing Odoo 11 (Community Edition) on Docker (Ubuntu 16.04),

    The error im getting are –

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 29: ordinal not in range(128)

    Not only this, the python print command terminates when trying to print Unicode characters:

    UnicodeEncodeError: 'ascii' codec can't encode characters...

    I found that Python 3 uses Unicode everywhere, which makes it inconvenient to use in an environment that claims not to support Unicode, such as these Docker images. This issue can be easily fixed by setting up systems default locale encoding to UTF-8, as:

    PROBLEM: Hit command ‘locale’ , and check the output:

    Directly execute these commands:

    or, add these lines in your DockerFile:

    Now, Hit command ‘locale’ , and check the output:

    That`s it…
    Thanks for reading this blog !!!

    Your opinions, comments and suggestions are important to keep this extension updated and more usefull !!!

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


  • Sunny Yadav
    Thanks, this fixed my issue (y)
  • Pedro Vagner
    Thank you for this post. But it doesn’t solve my problem.
    • Pedro Vagner
      I just solved my problem:

      RUN sed -i -e ‘s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/’ /etc/locale.gen &&
      sed -i -e ‘s/# pt_BR.UTF-8 UTF-8/pt_BR.UTF-8 UTF-8/’ /etc/locale.gen &&

      • Mohit Chandra
        I have tested this piece of code on Ubuntu (Xenial) only. Are you doing it on Ubuntu or Debian or any other os. Please confirm, so that i can update my blog as well 🙂
        Thanks for your feedback.
        • Pedro Vagner
          I’m using the official Odoo 11 Docker HUB ( It uses debian:stretch. It doesn’t include locale-gen utility. Here is the complete Docker snippet code:

          RUN set -x; apt-get update &&
          DEBIAN_FRONTEND=noninteractive apt-get install -y –no-install-recommends locales

          RUN sed -i -e ‘s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/’ /etc/locale.gen &&
          sed -i -e ‘s/# pt_BR.UTF-8 UTF-8/pt_BR.UTF-8 UTF-8/’ /etc/locale.gen &&

          ENV LANG en_US.UTF-8
          ENV LANGUAGE en_US.en
          ENV LC_ALL en_US.UTF-8

  • Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again