Closed
Description
I tried reading an hd5 file with the latest pandas and got this import error:
ImportError: Missing optional dependency 'pytables'. Use pip or conda to install pytables.
So I tried pip install pytables
and got this error:
ERROR: Could not find a version that satisfies the requirement pytables (from versions: none)
ERROR: No matching distribution found for pytables
So then I went searching on PyPI and apparently there are no packages named pytables
: https://pypi.org/search/?q=pytables
I did find the PyTables project on GitHub though, which says that we need to use pip install tables
to install it. After installing tables
, the hd5 read operation worked.
So, we need to install tables, not pytables, which is definitely confusing and not obvious. I think it would be very helpful if the error message indicated this to avoid having to go through the search process above.
Activity
user27182 commentedon May 30, 2025
Replacing these lines:
pandas/pandas/compat/_optional.py
Lines 151 to 157 in c708e15
with:
and also changing this lines:
pandas/pandas/compat/_optional.py
Line 73 in c708e15
to:
Produces a much clearer and more helpful error:
KevsterAmp commentedon May 31, 2025
Take
user27182 commentedon May 31, 2025
Just a heads up that I don't think the fix I suggested will work as-is... the install mapping has the form {"import name" : "PyPI package name"}
pandas/pandas/compat/_optional.py
Lines 62 to 74 in c708e15
but for PyTables, we do
import tables
andpip install tables
. So according to the mapping convention, this should betables : tables
for PyTables... which is redundant, and so PyTables should be removed from the mapping altogether if this convention is used.Instead, perhaps the mapping should be modified to include three names, with the import name as a key, and install name and colloquial name as a tuple for its value, e.g.:
And then inside of
import_optional_dependency
, do:rhshadrach commentedon May 31, 2025
PyTables uses
pytables
on conda andtables
on PyPI. If the current wording is confusing, I would propose we merely sayUse pip or conda to install the package
and leave it at that.user27182 commentedon May 31, 2025
It seems perhaps the issue is more with the naming conventions adopted by PyTables. I think this is the source of the confusion... and so perhaps it's not reasonable to expect pandas to make sure error messages account for the poor naming choices from third party packages.
The import error in this case is from
import tables
, so are you proposing changing thisTo this?
With no mention of the import name
tables
?To me the confusing part was that the message made no mention of
tables
yet that's both what I need to install (with pip) and import (with python), so this omission is part of the issue.Why not include both the key and value from the mapping dict in the message? That way, both
tables
andpytables
will be mentioned. That should give a hint to the user to try installing using one name, but if that fails then try installing using the other name.rhshadrach commentedon Jun 1, 2025
I'd be fine with
`import tables` failed, use pip or conda to install the pytables package
. But we shouldn't suggest the users look for either the import name nor the package name because as this example shows, it doesn't need to be either one.user27182 commentedon Jun 1, 2025
+1. This message is much clearer, and I think would resolve this issue.