AttributeError: ‘module’ object has no attribute ‘setdefaultencoding’

Python 3 has no sys.setdefaultencoding() function. It cannot be reinstated by reload(sys) like it can on Python 2 (which you really shouldn’t do in any case).

Since the default on Python 3 is UTF-8 already, there is no point in leaving those statements in.

In Python 2, using sys.setdefaultencoding() was used to plaster over implicit encoding problems (caused by concatening byte strings and unicode values, and other such mixed type situations), rather than fixing the problems themselves. Python 3 did away with implicit encoding and decoding, so using the plaster to set a different encoding would make no difference anyway.

However, if this is a 3rd-party library, then you probably will run into other problems as it clearly has not been made compatible with Python 3.

Leave a Comment