Reputation: 65
I'm getting two errors in tandem when trying to export a Pandas DataFrame to HDF5 on M1 Mac:
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/compat/_optional.py", line 126, in import_optional_dependency module = importlib.import_module(name) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'tables'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/casey/Documents/PythonProjects/untitled folder/json_load_test.py", line 19, in <module> objects.to_hdf('/Users/casey/Documents/PythonProjects/untitled folder/final.h5', key='objects') File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/generic.py", line 2775, in to_hdf pytables.to_hdf( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/io/pytables.py", line 311, in to_hdf with HDFStore( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/io/pytables.py", line 572, in init tables = import_optional_dependency("tables") File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/compat/_optional.py", line 129, in import_optional_dependency raise ImportError(msg) ImportError: Missing optional dependency 'pytables'. Use pip or conda to install pytables.
But when I try to install "tables" using PIP I get this message:
Requirement already satisfied: tables in /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages (3.7.0) Requirement already satisfied: numpy>=1.19.0 in /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages (from tables) (1.19.5) Requirement already satisfied: packaging in /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages (from tables) (21.3) Requirement already satisfied: numexpr>=2.6.2 in /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages (from tables) (2.8.1) Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages (from packaging->tables) (3.0.4)
And when using Conda to install "pytables" I get this message:
Collecting package metadata (current_repodata.json): done Solving environment: done
All requested packages already installed.
I've been stuck at this brick wall for a while now and just can't figure out how to proceed.
Upvotes: 2
Views: 1685
Reputation: 7996
Read error messages closely. You have 2 Python installations. They are different versions, and probably have different packages installed.
First message references /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10
.
Second message references /opt/homebrew/Caskroom/miniforge/base/lib/python3.9
.
(FYI, Macs come with Python installed -- this complicates your life.)
Solution is to be consistent. Either install Pandas in the 3.10 environment, OR run Python in the 3.9 environment.
Here are some techniques to verify which Python and package versions you are running:
# to get Python version:
import sys
print(sys.version)
# to get package version:
import package
print(package.__version__)
# where package is pandas, tables, etc
Conda and pip will list your packages and versions:
conda list (or conda list package_name)
pip list
Upvotes: 0