Encountered this problem, for Python 2.X:
1 import sys
2 reload(sys)
3 sys.setdefaultencoding( " utf-8 " )
For Python 3.3 and below:
1 import imp
2 imp.reload(sys)
requires attention:
1. There is a big difference between Python 3 and Python 2. The Python 3 system uses utf- 8 encoding by default .
2. So, for the case of using Python 3, the code of sys.setdefaultencoding( ” utf-8 ” ) is not needed.
3. The most important thing is that there is no setdefaultencoding() function in Python 3 sys library.
For Python 3.4 and above:
1 import importlib
2 importlib.reload(sys)
Similar Posts:
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- [Solved] DeprecationWarning: the imp module is deprecated in favour of importlib
- Python3 AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
- Python sublime3 [Decode error – output not utf-8] Chinese display problem
- Tensorflow ImportError: DLL load failed with error code -1073741795
- Install CDH6.2 agent error [How to Solve]
- Django startup error: generator expression must be parentized
- PIP install troubleshooting under Windows [How to Solve]
- Solve the problem of import error: cannot import name webriver
- error: invalid storage class for function