0

I'm using Jupyter Notebook to create a graph out of an xlsx file. the code works and the graph is shown correctly on Jupyter but when i try to launch the script from CLI i get this result :

λ python Untitled.py

Traceback (most recent call last):<br/> File "Untitled.py", line 25, in <module><br/> 
 df = pd.read_excel(workbook)<br/> File
 "C:\Python\lib\site-packages\pandas\util\_decorators.py", line 299, in
 wrapper<br/>   return func(*args, **kwargs)<br/> File
 "C:\Python\lib\site-packages\pandas\io\excel\_base.py", line 336, in
 read_excel<br/>   io = ExcelFile(io, storage_options=storage_options,
 engine=engine)<br/> File
 "C:\Python\lib\site-packages\pandas\io\excel\_base.py", line 1131, in
 __init__<br/>   self._reader = self._engines[engine](self._io, storage_options=storage_options)<br/> File
"C:\Python\lib\site-packages\pandas\io\excel\_xlrd.py", line 24, in
 __init__<br/>   import_optional_dependency("xlrd", extra=err_msg)<br/> File "C:\Python\lib\site-packages\pandas\compat\_optional.py", line
 109, in import_optional_dependency   raise ImportError(msg) from
 None<br/> ImportError: Missing optional dependency 'xlrd'. Install
 xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

The code is the following :

import pandas as pd
import matplotlib.pyplot as plt

workbook = "sample_scores.xlsx"

df = pd.read_excel(workbook)
print(df.head())

values = df[['Name','Test 1']]
print (values)

ax = values.plot.bar(x='Name', y='Test 1')
plt.show()

I installed pandas and matplotlib packages and also verified Python path and everything is set correctly but it seems I'm missing something?

3
  • 1
    just install xlrd module Commented Mar 21, 2021 at 17:02
  • After using pip install xlrd i had to use pip install openpyxl too to make it work . thanks! Commented Mar 21, 2021 at 17:08
  • yes and then pass engine='openpyxl' as parameter in pd.read_excel() method Commented Mar 21, 2021 at 17:09

1 Answer 1

1
!pip install xlrd

Install xlrd module

Sign up to request clarification or add additional context in comments.

2 Comments

I got this message : Your version of xlrd is {xlrd_version}. In xlrd >= 2.0, " ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead. i had to do 'pip install openpyxl' after it and now it worked. thanks !
Updated to modern practices, this should be %pip install xlrd (or openpyxl). See here for more about the modern %pip install & %conda install magic commands that insure the installation occurs in the environment backing the underlying kernel. The exclamation point alone doesn't do that, as covered in the top of the paragraph here, often causing issues/confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.