2

I'm trying to read an excel file in freshly installed pandas using read_excel function.

Unfortunately, it raises an error:

cities_xlsx = pandas.read_excel(cities_xlsx_path)

~/.virtualenvs/osobnimakleri2/lib/python3.8/site-packages/defusedxml/common.py in iterparse(source, events, parser, forbid_dtd, forbid_entities, forbid_external)
    103                   forbid_entities=True, forbid_external=True):
    104         if parser is None:
--> 105             parser = DefusedXMLParser(target=_TreeBuilder(),
    106                                       forbid_dtd=forbid_dtd,
    107                                       forbid_entities=forbid_entities,

~/.virtualenvs/osobnimakleri2/lib/python3.8/site-packages/defusedxml/ElementTree.py in __init__(self, html, target, encoding, forbid_dtd, forbid_entities, forbid_external)
     66                  forbid_external=True):
     67         # Python 2.x old style class
---> 68         _XMLParser.__init__(self, html, target, encoding)
     69         self.forbid_dtd = forbid_dtd
     70         self.forbid_entities = forbid_entities

TypeError: __init__() takes 1 positional argument but 4 were given

Module versions:

Python 3.8.5
xlrd==1.2.0
pandas==1.1.4

Do you know where is the problem?

Milano
  • 18,048
  • 37
  • 153
  • 353
  • This could be useful https://github.com/tiran/defusedxml/issues/34 as to the cause of the problem – buran Nov 07 '20 at 08:20
  • I researched a lot about the problem and the solution that worked for me was updating all the python modules to the latest version. Below is the snippet that i used for updating the modules. pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U Taken from https://stackoverflow.com/questions/2720014/how-to-upgrade-all-python-packages-with-pip – shyamzzp Feb 02 '21 at 07:09

2 Answers2

2

I've downgraded XLRD to version 1.1.0 and it's working now.

pip install xlrd==1.1.0
Milano
  • 18,048
  • 37
  • 153
  • 353
0

If you are using Python version 3.8 and above, update all pip dependencies. This should resolve it. Update all pip dependencies using either of the commands below:

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U

or

pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
Elijah Baraza
  • 291
  • 4
  • 4