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

in this post, i am going to explain how to fix  AttributeError: ‘module’ object has no attribute ‘setdefaultencoding’ error in python 2.7.

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

 

import nltk
import os
from tkinter import *
from tkinter import ttk
import docx2txt
from tkinter.filedialog import askopenfilename
from tkinter import Tk, Entry, Button, INSERT
from tkinter import messagebox
import sys
from imp import reload
reload(sys)
sys.setdefaultencoding("utf-8")

 

 

import time from selenium import webdriver import codecs import sys reload(sys) sys.setdefaultencoding('utf-8')

how to solve this problem

we can use

import sys
from imp import reload
if sys.version[0] == '2':
    reload(sys)
    sys.setdefaultencoding("utf-8")


in place of 

import sys
from imp import reload
reload(sys)
sys.setdefaultencoding("utf-8")

 

Python 3 doesn’t have  sys.setdefaultencoding() function. Python 3 already has default UTF-8.

you are getting problem as AttributeError: ‘module’ object has no attribute ‘setdefaultencoding’ . you can use in python 2.7

if sys.version[0] == '2':
    reload(sys)
    sys.setdefaultencoding("utf-8")

 

if u have another solution to solve this problem and if you have tried it, please write in a comment and help to other . or if you are still getting same problem don’t forget to write, i will try my best to solve to your problem.

Reference:- Stackoverflow


you may also like

Python Program to Calculate Simple Interest using function


 

Leave a Reply

Your email address will not be published. Required fields are marked *