Python sets the default encoding to utf8, Which is pythonutf8.
This example describes how to set the default encoding to utf8 in Python. We will share this with you for your reference. The details are as follows:
This is a Python encoding problem. Set the default python encoding to utf8.
Python installation directory:/etc/python2.x/sitecustomize. py
Import sysreload (sys) sys. setdefaultencoding ('utf-8') try: import apport_python_hookhandle t ImportError: passelse: apport_python_hook.install ()
In windows:
You can create a new sitecustomize In the Lib/site-packages directory under the Python installation directory. py file (you can also create it elsewhere, and then manually import it here. The setting will automatically take effect each time you start Python). The content is as follows:
Import syssys. setdefaultencoding ('utf-8') # set default encoding to UTF-8
Then you can see that the change has taken effect.
>>> Import sys >>> sys. getdefaultencoding () 'utf-8'
At this time, run the program. If the previous error is still reported, you only need to set the output encoding explicitly.
Print s. encode ('utf-8 ')
You can see the correct display.