' ASCII ' codec can't encode characters in position 162-165:ordinal not in range
aaa.py file is already set
#!/usr/bin/env Python3
# coding = ' Utf-8 '
But execution always gets an error.
' ASCII ' codec can ' t encode characters in position 162-165:ordinal not in range (128)
After the online query this kind of error is basically 2.7 of the problem in the environment, through the following methods to solve.
- # Encoding=utf8
- Import Sys
- Reload (SYS)
- Sys.setdefaultencoding (' UTF8 ')
But why am I always wrong in the PYTHON3 environment?
By modifying the code in the codec Chinese and other operations are not valid, toss half a day to consider whether there is a Linux language environment variable problem
Check the current shell environment
$ echo $SHELL
Csh
Check locale variables
$ env |grep LANG
Lang=zh
Change the language environment variable to
Setenv LANG en_US. UTF-8
Problem solving
Python3 Coding errors under Linux