python - 属性错误 : 'module' object has no attribute 'File' for h5py

标签 python h5py

所以这是我的代码的开头:

#!/usr/bin/python

import h5py
f = h5py.File("/data/vera/run-2/hdfaa.001","r")

当我运行它时,它在主目录中运行良好。但是当我在主目录中的目录中运行它时,会打印错误:

Traceback (most recent call last):
File "h5py.py", line 3, in <module>
import h5py
File "/.../h5py.py", line 5, in <module>
f = h5py.File("/...","r")
AttributeError: 'module' object has no attribute 'File'

当我使用 python 解释器的 IPython 时,它可以导入库并具有属性 h5py.File。但是一旦我解释了脚本,解释器就不能再导入 h5py 库了。删除文件后,它又可以正常工作了。

我已经使用解释器检查了我的脚本,脚本应该没有任何问题。

由于我对 python 很陌生,所以我不知道哪里出了问题。

最佳答案

这对我有用:

  • 卸载 h5py : pip uninstall h5py
  • 安装 h5py : pip install h5py

实际上我检查了已经存在的 h5py 包,我觉得它似乎已损坏。所以我做了显而易见的事情,瞧,它奏效了!

关于python - 属性错误 : 'module' object has no attribute 'File' for h5py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42593286/

相关文章:

python - 更新键而不影响嵌套字典中键的值

python - 使用 Flask 保存并发送大型 numpy 数组

python - HDF5 文件名称中的 '/' 混淆

dictionary - 一步高效地将 h5py 属性复制到 python dict

python - 无法打开之前打开的H5

python - 使用 Python 的 HDF 文件中的数据丢失

python - Heroku:更改 requirements.txt 后出现 "directory exists"错误

python - 如何使用 Django-MongoDB 引擎根据模型上 DictField 中的字典内容进行过滤?

python - Pandas /Python : How to Transpose Duplicate Rows to Columns and Preserve Order?

Python 和 Pandas : How to round Up/Down unix timestamp (utc) on different resolutions: 1min-5min-15min-30min-1H-1D?