0

On jupyter notebook

import pandas as pd
df= pd.read_excel("teste.xlsx")

ERROR

Traceback (most recent call last):

  File "C:\Users\ngn19\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-2-86a606b82519>", line 1, in <module>
    df= pd.read_excel("teste.xlsx")

  File "C:\Users\ngn19\anaconda3\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
    io = ExcelFile(io, engine=engine)

  File "C:\Users\ngn19\anaconda3\lib\site-packages\pandas\io\excel\_base.py", line 821, in __init__
    self._reader = self._engines[engine](self._io)

  File "C:\Users\ngn19\anaconda3\lib\site-packages\pandas\io\excel\_xlrd.py", line 20, in __init__
    import_optional_dependency("xlrd", extra=err_msg)

  File "C:\Users\ngn19\anaconda3\lib\site-packages\pandas\compat\_optional.py", line 89, in import_optional_dependency
    module = importlib.import_module(name)

  File "C:\Users\ngn19\anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import

  File "<frozen importlib._bootstrap>", line 983, in _find_and_load

  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 724, in exec_module

  File "<frozen importlib._bootstrap_external>", line 860, in get_code

  File "<frozen importlib._bootstrap_external>", line 791, in source_to_code

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "C:\Users\ngn19\anaconda3\lib\site-packages\xlrd\__init__.py", line 1187
    print "EXTERNSHEET(b7-):"
                            ^
SyntaxError: invalid syntax
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
NGN
  • 1
  • 1
    That's Python 2 code. It can't be used with Python 3 -- make sure you're using a version of xlrd built for Python 3. – Charles Duffy Apr 22 '21 at 17:08
  • What would be the correct code for python3? Do I need to update the Anaconda or Pandas library? – NGN Apr 22 '21 at 17:19
  • It's specifically the `xlrd` library that's too old -- maybe others too, but that one for sure. In Python 3, it needs to be `print("something")` instead of `print "something"`. – Charles Duffy Apr 22 '21 at 17:35
  • It does look like it's pandas that uses xlrd, but that doesn't _definitely_ mean pandas is too old also; depends on exactly how everything got installed. – Charles Duffy Apr 22 '21 at 17:35

0 Answers0