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

后端 未结 3 741
遇见更好的自我
遇见更好的自我 2021-01-31 15:08

I downloaded Quokka Python/Flask CMS to a CentOS7 server. Everything works fine with command

sudo python3 manage.py runserver --host 0.0.0.0 --port 80

相关标签:
3条回答
  • 2021-01-31 15:32

    Adding more to the existing solutions:

    If you see something like this error in Python 3:

    Traceback (most recent call last):
      ...
    RuntimeError: Click will abort further execution because Python 3 was
      configured to use ASCII as encoding for the environment. Either switch
      to Python 2 or consult http://click.pocoo.org/python3/ for
      mitigation steps.
    

    You are dealing with an environment where Python 3 thinks you are restricted to ASCII data. The solution to these problems is different depending on which locale your computer is running in.

    For instance, if you have a German Linux machine, you can fix the problem by exporting the locale to de_DE.utf-8:

    export LC_ALL=de_DE.utf-8
    export LANG=de_DE.utf-8
    

    If you are on a US machine, en_US.utf-8 is the encoding of choice. On some newer Linux systems, you could also try C.UTF-8 as the locale:

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

    Taken from the Python 3 Surrogate Handling

    0 讨论(0)
  • 2021-01-31 15:45

    If you are trying to execute tests case you must set the following environment variables each time:

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

    Doing this each time will resolve the error.

    It may also be possible to set this in your IDE run configuration as

    LC_ALL=en_US.UTF-8;LANG=en_US.UTF-8
    

    For example see the following setting in PyCharm 2016:

    0 讨论(0)
  • 2021-01-31 15:55

    At the top of your Python script, try to put

    export LC_ALL=en_US.utf-8
    export LANG=en_US.utf-8
    
    0 讨论(0)
提交回复
热议问题