PrettyTable
raw JSON → 3.17.0 verified Tue May 12 auth: no python install: verified quickstart: verified
PrettyTable is a Python library for easily displaying tabular data in a visually appealing ASCII table format. It supports various output formats including ASCII, HTML, CSV, JSON, LaTeX, and MediaWiki. The library is actively maintained with regular releases, currently at version 3.17.0.
pip install prettytable Common errors
error ModuleNotFoundError: No module named 'prettytable' ↓
cause The 'prettytable' package is not installed in the Python environment where the script is being executed.
fix
pip install prettytable
error AttributeError: 'module' object has no attribute 'PrettyTable' ↓
cause A local Python file named 'prettytable.py' exists in the same directory as your script, shadowing the installed 'prettytable' library and preventing the correct module from being imported.
fix
Rename your local file from 'prettytable.py' to something else (e.g., 'my_table_script.py') and delete any associated '.pyc' files.
error TypeError: PrettyTable.add_row() takes 2 positional arguments but X were given ↓
cause The 'add_row()' method expects a single iterable (like a list or tuple) containing all the values for the row as its argument, but individual values are being passed as separate arguments.
fix
Pass a list or tuple of values to 'add_row()', for example:
table.add_row([value1, value2, value3]). error AttributeError: 'module' object has no attribute 'set_field_names' ↓
cause The 'set_field_names()' method was deprecated and removed in PrettyTable version 0.6. Field names are now set directly via the 'field_names' attribute.
fix
Instead of
table.set_field_names(['Header 1', 'Header 2']), use table.field_names = ['Header 1', 'Header 2']. Warnings
breaking PrettyTable 3.17.0 dropped support for Python 3.9. Users on Python 3.9 or older should use an earlier version of PrettyTable (e.g., 3.16.0 or below) or upgrade their Python interpreter. ↓
fix Upgrade Python to 3.10+ or pin `prettytable<3.17.0`.
deprecated The direct constants `hrule` and `tableStyle` were deprecated in version 3.12.0. Use the corresponding enum values from `HRuleStyle`, `VRuleStyle`, and `TableStyle` instead for clarity and type safety. ↓
fix Replace `prettytable.FRAME` with `HRuleStyle.FRAME` or `TableStyle.DEFAULT` etc. as appropriate.
gotcha `ModuleNotFoundError: No module named 'prettytable'` is a common issue, often caused by installing `prettytable` in a different Python environment (e.g., virtual environment) than the one your IDE or script is using. ↓
fix Ensure `pip install prettytable` is run in the *same* Python environment where your script is executed. Verify the active Python interpreter in your IDE.
gotcha Prior to 3.15.1, `add_rows()` could raise an `IndexError` if provided with an empty list that was not handled gracefully. ↓
fix Upgrade to `prettytable>=3.15.1` or ensure the list passed to `add_rows()` is not empty before calling.
gotcha In versions prior to 3.14.0, specifying `sortby` directly at class declaration might not have been correctly applied, requiring it to be set after instantiation or via `get_string()` arguments. ↓
fix Upgrade to `prettytable>=3.14.0` or set `sortby` explicitly on the table instance (`table.sortby = "Column"`) after initialization or when calling `get_string()`.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.06s 18.7M
3.10 alpine (musl) - - 0.05s 18.6M
3.10 slim (glibc) wheel 1.6s 0.07s 19M
3.10 slim (glibc) - - 0.08s 19M
3.11 alpine (musl) wheel - 0.07s 20.6M
3.11 alpine (musl) - - 0.08s 20.5M
3.11 slim (glibc) wheel 1.7s 0.08s 21M
3.11 slim (glibc) - - 0.06s 21M
3.12 alpine (musl) wheel - 0.05s 12.5M
3.12 alpine (musl) - - 0.06s 12.3M
3.12 slim (glibc) wheel 1.6s 0.06s 13M
3.12 slim (glibc) - - 0.06s 13M
3.13 alpine (musl) wheel - 0.05s 12.2M
3.13 alpine (musl) - - 0.05s 12.0M
3.13 slim (glibc) wheel 1.6s 0.05s 13M
3.13 slim (glibc) - - 0.05s 12M
3.9 alpine (musl) wheel - 0.02s 18.2M
3.9 alpine (musl) - - 0.03s 18.1M
3.9 slim (glibc) wheel 1.9s 0.02s 19M
3.9 slim (glibc) - - 0.02s 19M
Imports
- PrettyTable
from prettytable import PrettyTable - ColorTable
from prettytable.colortable import ColorTable - TableStyle
from prettytable import TableStyle
Quickstart verified last tested: 2026-04-24
from prettytable import PrettyTable
table = PrettyTable()
table.field_names = ["City name", "Area", "Population"]
table.add_row(["Adelaide", 1295, 1158259])
table.add_row(["Brisbane", 5905, 1857594])
table.add_row(["Sydney", 2058, 4336374])
print(table)
# Example with alignment and style
table.align["City name"] = "l"
table.align["Population"] = "r"
# To use custom styles, import TableStyle
from prettytable import TableStyle
table.set_style(TableStyle.MARKDOWN)
print(table)