python h5py文件读取 "OSError: Unable to open file (bad superblock version number)"

标签 python linux windows hdf5 h5py

简短描述

我有一个 hdf5 文件已经在 Windows 机器上写入并且无法在 Linux 机器上打开的问题。错误消息是“OSError:无法打开文件(错误的 super block 版本号)”。 (因此,这个问题可能与 h5py 根本无关,而是 python 文件打开时的一般 linux/windows 兼容性问题)。

详细说明

在 Windows 和 Linux 上都使用了具有以下软件包的 python 虚拟环境:

  • flask -0.12.2
  • flask -RESTful-0.3.6
  • Jinja2-2.10
  • MarkupSafe-1.0
  • Werkzeug-0.14.1
  • aniso8601-3.0.0
  • 点击-6.7
  • h5py-2.7.1
  • h5py-cache-1.0
  • itsdangerous-0.24
  • 锁文件-0.12.2
  • numpy-1.14.0
  • pytz-2018.3
  • 6-1.11.0

在 Windows 上,可以毫无问题地打开和读取文件,但在 Linux 上却不能,抛出 OSError。只需启动一个新的 python session 并键入以下内容就足够了:

import h5py

f1 = h5py.File("myfile.hdf5", "r")

完整错误:

Traceback (most recent call last):

File "stdin", line 1, in module

File "/usr/local/lib/python3.6/site-packages/h5py/_hl/files.py", line 312, in _ _ init_ _

fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)

文件“/usr/local/lib/python3.6/site-packages/h5py/_hl/files.py”,第 142 行,make_fid

fid = h5f.open(name, flags, fapl=fapl)

文件“h5py/_objects.pyx”,第 54 行,在 h5py._objects.with_phil.wrapper 中

文件“h5py/_objects.pyx”,第 55 行,在 h5py._objects.with_phil.wrapper 中

文件“h5py/h5f.pyx”,第 78 行,在 h5py.h5f.open 中

OSError:无法打开文件(错误的 super block 版本号)

HDF5 文件是在 Windows 机器上使用 Java HDF5 库从我无法修改的程序中编写的,hdf5 java 1.10.0 处于 SWMR(单写,多读取器)模式。

在将文件进一步发送到我的程序(一个轻量级 Linux 应用程序)之前,程序可能没有正确关闭文件。

http://web.mit.edu/fwtools_v3.1.0/www/H5.format.html ,“ super block 的版本号”描述如下...

This value is used to determine the format of the information in the super block. When the format of the information in the super block is changed, the version number is incremented to the next integer and can be used to determine how the information in the super block is formatted.

Values of 0 and 1 are defined for this field.

This field is present in version 0+ of the superblock.

...这无法帮助我理解错误的 super block 版本号错误可能是什么。

这是我尝试打开的示例文件: https://drive.google.com/open?id=10hpbWj4HBwIMq0X6Rq7yVzJATOiYHJcc

为什么要从中提出一个 stackoverflow 问题?

这个问题可能会影响所有在 Linux 机器上想要读取在 Windows 机器上生成但未正确关闭/格式化/等的 hdf5 文件的人。我想知道发生这种情况的原因以及如何在我的 Linux 上解决这个问题。如果唯一的解决方案是“它需要由生成 HDF5 文件的 Windows 程序修复,因为之后无法修复”,那么这也是一个可以接受的答案。这里是这样吗?

采取的行动

  • 将 h5py 升级到 2.8.0rc1 并不能解决问题
  • 可以正常打开其他HDF5文件

相关主题

出于可能的原因,我查看了以下主题和网站,但一无所获:

1) https://support.hdfgroup.org/HDF5/faq/bkfwd-compat.html

2) h5py OSError: Unable to open file (File signature not found)

3) HDF5 file created with h5py can't be opened by h5py

4) https://github.com/h5py/h5py/issues/757

5) http://web.mit.edu/fwtools_v3.1.0/www/H5.format.html

编辑 1:

感谢@Tom de Geus,我在 Linux 和 Windows 上尝试了 HDF View,发现示例文件在 Linux HDF View 上无法打开,但可以在 Windows HDF View 上打开。这表明问题出在文件和 HDF 中,而不是 h5py。

最佳答案

感谢 Pierre de Buyl 确认文件确实可以在 Linux 上使用正确的 HDF 版本 1.10.0 打开。在 Windows 上,我运行的是 HDF 1.10.1(通过 h5py 安装),但在 Linux 上,h5py 的默认安装给了我 1.8.18。使用 cmake 从源构建 HDF 后,我也能够在 Linux 上打开该文件,版本为 1.10.0 或更高版本。

使用 cmake 安装 HDF 1.10.0 的指南: https://support.hdfgroup.org/HDF5/release/cmakebuild.html

错误信息“OSError: Unable to open file (bad superblock version number)”令人困惑,但似乎表明旧版本的 HDF (1.8.18) 没有配置为识别新的 super block 版本号HDF 版本 1.10.0。

感谢 Tom de Geus 和 Pierre de Buyl 的帮助:)

关于python h5py文件读取 "OSError: Unable to open file (bad superblock version number)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49386121/

相关文章:

c++ - 如何从 LPCTSTR 转换为 LPSTR?

windows - 将 gradle 构建移动到另一台机器

python - Tensorflow - 关于 mnist.train.next_batch()

python - 在不同的函数中使用字符串的名称

linux - 在 linux 屏幕中保留我的环境

c - 尝试使用 semget() 获取信号量集,但我不断收到 EEXIST 错误,即使在创建新 key 后也是如此

windows - 如何从我的计算机上卸载 powershell 模块?

python - 为什么这个容器不能正常运行?

python - 窗口框架中的标签不会拉伸(stretch),为什么?

linux - 在哪里放置 shell 脚本/函数? .bashrc 还是 bin?