Last modified: Jun 01, 2025 By Alexander Williams

Install xlrd and xlwt in Python Easily

Working with Excel files in Python is easy with xlrd and xlwt. These libraries help read and write Excel files. This guide will show you how to install them.

What Are xlrd and xlwt?

xlrd is a library for reading Excel files. It supports .xls and .xlsx formats. xlwt is used to write Excel files. It works with .xls format.

These libraries are useful for data analysis and automation. If you work with Excel files, they are must-have tools.

Prerequisites

Before installing, ensure you have Python installed. Check your Python version using the command below.


import sys
print(sys.version)


3.9.7 (default, Sep 16 2021, 16:59:28) 
[GCC 10.2.1 20210110]

You also need pip, Python's package installer. Verify pip is installed with this command.


pip --version


pip 21.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Install xlrd in Python

Use pip to install xlrd. Run the following command in your terminal.


pip install xlrd

After installation, verify it works. Open Python and import the library.


import xlrd
print("xlrd installed successfully!")


xlrd installed successfully!

Install xlwt in Python

Install xlwt using pip. Run this command in your terminal.


pip install xlwt

Check if the installation was successful. Import the library in Python.


import xlwt
print("xlwt installed successfully!")


xlwt installed successfully!

Basic Usage Examples

Now, let's see how to use these libraries. First, read an Excel file with xlrd.


import xlrd

# Open the workbook
workbook = xlrd.open_workbook("example.xls")

# Get the first sheet
sheet = workbook.sheet_by_index(0)

# Read a cell value
print(sheet.cell_value(0, 0))


"Hello, Excel!"

Next, write an Excel file with xlwt.


import xlwt

# Create a new workbook
workbook = xlwt.Workbook()

# Add a sheet
sheet = workbook.add_sheet("Sheet1")

# Write to a cell
sheet.write(0, 0, "Hello, Excel!")

# Save the file
workbook.save("output.xls")

This creates a file named output.xls with your data.

Common Issues and Fixes

Sometimes, you may face errors. Here are common ones and their fixes.

Error: No module named 'xlrd'

This means xlrd is not installed. Run pip install xlrd again.

Error: Unsupported format

xlrd no longer supports .xlsx files. Use openpyxl for .xlsx files.

For more advanced Excel tasks, check our guide on Install python-pptx for PowerPoint Automation.

Alternative Libraries

If xlrd and xlwt don't meet your needs, try these alternatives.

openpyxl - Works with .xlsx files.

pandas - Great for data analysis.

For big data tasks, see Install PyTables for Big Data in Python.

Conclusion

Installing xlrd and xlwt in Python is simple. These libraries make Excel file handling easy.

Follow the steps above to get started. For more Python tools, explore Install python-docx for Word Documents in Python.