Query system default encoding for the interpreter, enter the following command:
Set the default encoding to use:
May be reported AttributeError: 'module' object has no attribute 'setdefaultencoding' error, do the reload (sys), in the above command to pass.
At this point in the implementation of sys.getdefaultencoding () will find that has been set to utf8 encoding of, but in changes in the code interpreter can only be guaranteed when the second effective after restarting the interpreter, you will find they are reset code ascii as the default, then there is no way to modify the program or system once the default encoding it.
There are 2 ways to set the default python code:
A solution to the problem in the program by adding the following code:
import sys reload(sys) sys.setdefaultencoding('utf8')
Another option is the python's Lib \ site-packages folder, create a new sitecustomize.py, says:
# encoding=utf8 import sys reload(sys) sys.setdefaultencoding('utf8')
Then restart the python interpreter, the implementation of sys.getdefaultencoding (), that has been set to utf8 encoding of the many times after a reboot, the same effect, because when the system starts in python, called the document itself, set system default encoding, without the need to manually add each address code, is once and for all solution.
Another solution is involved in the program code where all the mandatory encoding utf8, which add code encode ("utf8"), this method is not recommended, because once a place to write less, will result in a large number of error report, I have encountered this situation, error log compressed still more than 70 K, all this problem, people feel there are crashes.