To use the xlrd library for Python on Ubuntu, you typically need to install it via pip. However, there is a major caveat with modern versions of this library that you need to be aware of before starting.

Here is the complete guide for Ubuntu.
The Critical Warning (xlrd 2.0+)
If you are following an old tutorial or using legacy code, you will likely encounter errors.
Since version 2.0, xlrd only supports .xls (Excel 2003 and older) files.
It no longer supports .xlsx files.
- If your file is .xls: Use
xlrd. - If your file is .xlsx: Use
openpyxlorpandas(which usesopenpyxlinternally).
Installation on Ubuntu
Open your terminal (Ctrl+Alt+T) and follow these steps.

Step 1: Install Python Pip (if you haven't already) For Python 3 (standard on modern Ubuntu):
sudo apt update sudo apt install python3-pip
Step 2: Install xlrd
pip3 install xlrd
(Note: If you get a permission error, run pip3 install xlrd --user or use a virtual environment).
Basic Usage Example (Reading .xls files)
Here is a simple Python script to read an .xls file.

Create a file named read_excel.py:
import xlrd
# Path to your .xls file
file_path = 'my_spreadsheet.xls'
try:
# Open the workbook
workbook = xlrd.open_workbook(file_path)
# Open the first sheet by index
sheet = workbook.sheet_by_index(0)
# Read a specific cell (Row 0, Column 0)
cell_value = sheet.cell_value(0, 0)
print(f"Cell A1: {cell_value}")
# Loop through all rows
print("\n--- All Rows ---")
for row_idx in range(sheet.nrows):
row = sheet.row(row_idx)
print(row)
except FileNotFoundError:
print("File not found.")
except xlrd.biffh.XLRDError:
print("This file is likely .xlsx. xlrd 2.0+ does not support .xlsx.")
Run it:
python3 read_excel.py
Alternative: If you MUST read .xlsx files
If you try to use xlrd on an .xlsx file, you will get an error: xlrd.biffh.XLRDError: Excel xlsx file; not supported.
You should switch to openpyxl instead.
Install:
pip3 install openpyxl
Code Example:
import openpyxl
# Load the workbook
wb = openpyxl.load_workbook('my_spreadsheet.xlsx')
# Select the active sheet
sheet = wb.active
# Read cell A1
print(sheet['A1'].value)
Using Pandas (The Easiest Way)
If you are doing data analysis, use pandas. It handles the backend library switching automatically.
pip3 install pandas openpyxl xlrd
import pandas as pd
# Reads .xls using xlrd automatically
# Reads .xlsx using openpyxl automatically
df = pd.read_excel('my_spreadsheet.xlsx')
print(df.head()) 