Python“表”模块“未找到”,但 PIP 和 Conda 表示已安装
当试图将PANDAS DataFrame导出到M1 Mac上的HDF5时,我会遇到两个错误:
追溯(最近的最新通话): 文件“/library/frameworks/python.framework/3.10/lib/python3.10/site-packages/pandas/pandas/compat/_optional.py” 模块= ementlib.import_module(name) 文件“/library/frameworks/python.framework/versions/3.10/lib/python3.10/importlib/portlib/< strong> init> init .py”,第126行,in Import_Module 返回_bootstrap._gcd_import(name [level:],软件包,级别) file“&lt; frozen expitionlib._bootstrap&gt;“,第1050行,in _gcd_import file“&lt; frozen expitionlib._bootstrap&gt;“,第1027行,in _find_and_load中 file“&lt; frozen expitionlib._bootstrap&gt;“,第1004行,in _find_and_load_unlocked ModulenotFoundError:没有名为“表”的模块
在处理上述例外时,发生了另一个例外:
追溯(最近的最新通话): 文件“/users/casey/documents/pythonprojects/untitled文件夹/json_load_test.py”,第19行,in&lt; module&gt; objects.to_hdf('/users/casey/documents/pythonprojects/pythonprojects/untitled文件夹/final.h5',key ='objects') 文件“/library/frameworks/python.framework/versions/3.10/lib/python3.10/site-packages/pandas/pandas/core/generic.py”,第2775行,在to_hdf pytable.to_hdf( 文件“/library/frameworks/python.framework/versions/3.10/lib/python3.10/site-packages/pandas/pandas/io/pytables.py”,第311行,在to_hdf 使用HDFSTORE( 文件“/library/frameworks/python.framework/3.10/lib/python3.10/site-packages/pandas/pandas/io/pytables.py”,第572行,in init 表= import_optional_dependenty(“表”) 文件“/library/frameworks/python.framework/3.10/lib/python3.10/site-packages/pandas/pandas/compat/_optional.py” 提高Importerror(MSG) Importerror:缺少可选的依赖性“ Pytables”。使用PIP或CONDA安装Pytable。
但是,当我尝试使用PIP安装“表”时,我会收到此消息:
需求已经满足:餐桌/homebrew/caskroom/miniforge/base/base/lib/python3.9/site-packages(3.7.0) 需求已经满足:numpy&gt; = 1.19.0 in/opt/homebrew/caskroom/miniforge/base/base/lib/python3.9/site-packages(来自表)(1.19.5) 需求已经满足:在/opt/homebrew/caskroom/miniforge/base/lib/python3.9/site-packages(来自表)(21.3)(21.3) 需求已经满足:numExpr&gt; = 2.6.2 in/opt/homebrew/caskroom/miniforge/base/base/lib/python3.9/site-packages(来自表)(2.8.1) 需求已经满足:pyparsing!= 3.0.5,&gt; = 2.0.2 in/opt/homebrew/caskroom/miniforge/miniforge/miniforge/base/lib/python3.9/site-packages(来自包装 - &gt; tables)(3.0.4.4.4 )
,当使用conda安装“ Pytables”时,我会收到此消息:
收集软件包元数据(current_repodata.json):完成 解决环境:完成
所有已要求的软件包已经安装了。
我已经被困在这座砖墙上了一段时间,只是不知道如何进行。
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: doneAll 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
密切阅读错误消息。您有2个Python安装。它们是不同的版本,可能安装了不同的软件包。
第一个消息参考
/library/frameworks/python.framework/versions/3.10/lib/python3.10
。第二个消息参考
/opt/homebrew/caskroom/miniforge/base/base/lib/python3.9
。(仅供参考,Mac随附Python安装 - 这使您的生活变得复杂。)
解决方案是一致的。要么在3.10环境中安装熊猫,要么在3.9环境中运行python。
以下是您正在运行的Python和软件包版本的一些技术:
Conda和Pip将列出您的软件包和版本:
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:
Conda and pip will list your packages and versions: