尝试打开h5py文件,返回errorno = 17,错误消息='文件存在'

问题描述 投票:2回答:2

import numpy as np import h5py

用h5py.File(“testfile.hdf5”,“w-”)作为f:arr = np.ones((5,2))f [“my dataset”] = arr dset = f [“my dataset”]

此代码第一次正确运行,但第二次运行时,返回以下错误:

%运行“C:\ Users \ James \ Google Drive \ Python Scripts \ Python和HDF5 \ Chapter3.py”-------------------------- ------------------------------------------------- RuntimeError回溯(最近一次调用最后一次)C:\ Users \ James \ Google Drive \ Python Scripts \ Python和HDF5 \ Chapter3.py in()6,其中h5py.File(“testfile.hdf5”)为f:7 arr = np。其中((5,2))----> 8 f [“我的数据集”] = arr 9 dset = f [“我的数据集”] 10

h5py._objects.with_phil.wrapper中的h5py_objects.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py_objects.c:2696)()

h5py._objects.with_phil.wrapper中的h5py_objects.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py_objects.c:2654)()

setitem中的C:\ Users \ James \ AppData \ Local \ Enthought \ Canopy \ User \ lib \ site-packages \ h5py_hl \ group.py(self,name,obj)291 else:292 ds = self.create_dataset(无,数据= obj,dtype = base.guess_dtype(obj)) - > 293 h5o.link(ds.id,self.id,name,lcpl = lcpl)294 295 @with_phil

h5py._objects.with_phil.wrapper中的h5py_objects.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py_objects.c:2696)()

h5py._objects.with_phil.wrapper中的h5py_objects.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py_objects.c:2654)()

h5py.h5o.link中的h5py \ h5o.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py \ h5o.c:3610)()

RuntimeError:无法创建链接(名称已存在)

%运行“C:\ Users \ James \ Google Drive \ Python Scripts \ Python和HDF5 \ Chapter3.py”-------------------------- ------------------------------------------------- IOError回溯(最近一次调用最后一次)C:\ Users \ James \ Google Drive \ Python Scripts \ Python和HDF5 \ Chapter3.py in()4 from timeit import timeit 5 ----> 6 with h5py.File(“testfile。 hdf5“,”w-“)为f:7 arr = np.ones((5,2))8 f [”my dataset“] = arr

init中的C:\ Users \ James \ AppData \ Local \ Enthought \ Canopy \ User \ lib \ site-packages \ h5py_hl \ files.py(self,name,mode,driver,libver,userblock_size,swmr,** kwds)270 271 fapl = make_fapl(driver,libver,** kwds) - > 272 fid = make_fid(name,mode,userblock_size,fapl,swmr = swmr)273 274如果swmr_support:

make_fid中的C:\ Users \ James \ AppData \ Local \ Enthought \ Canopy \ User \ lib \ site-packages \ h5py_hl \ files.py(name,mode,userblock_size,fapl,fcpl,swmr)94 fid = h5f.open(名称,h5f.ACC_RDWR,fapl = fapl)95 [el-','x']中的elif模式:---> 96 fid = h5f.create(name,h5f.ACC_EXCL,fapl = fapl,fcpl = fcpl) 97 elif mode =='w':98 fid = h5f.create(name,h5f.ACC_TRUNC,fapl = fapl,fcpl = fcpl)

h5py._objects.with_phil.wrapper中的h5py_objects.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py_objects.c:2696)()

h5py._objects.with_phil.wrapper中的h5py_objects.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py_objects.c:2654)()

h5py.h5f.crex中的h5py \ h5f.pyx(C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py \ h5f.c:2109)()

IOError:无法创建文件(无法打开文件:name ='testfile.hdf5',errno = 17,错误消息='文件存在',标志= 15,o_flags = 502)

代码和错误在Canopy // Python 3.5中运行。我也在Spyder中运行它并收到相同的结果。我也试过用

用h5py.File(“testfile.hdf5”,“a”)作为f:

没有成功。

python numpy h5py
2个回答
1
投票

根据http://docs.h5py.org/en/latest/high/file.htmlw-模式旨在使文件已存在时打开操作失败。


0
投票

当我在HDF5Matrix(v2.2.2)中使用keras类时,我遇到了完全相同的错误消息。但是,当我有多个训练过程都需要访问磁盘上相同的HDF5数据时,我找不到完全避免此错误的成熟解决方案。只有一个进程可以成功访问此HDF5数据,而所有其他进程都会报告相同的错误,即使我将读取模式从默认的r+修改为r。我放弃并使用了可行的解决方案,该解决方案保留了HDF5数据的多个副本以及每个培训过程的一个副本。

© www.soinside.com 2019 - 2024. All rights reserved.