问题描述
,其中h5py.File("testfile.hdf5","w-")为f: arr = np.ones((5,2)) f [我的数据集"] = arr dset = f [我的数据集"]
with h5py.File("testfile.hdf5", "w-") as f: arr = np.ones((5,2)) f["my dataset"] = arr dset = f["my dataset"]
此代码第一次正确运行,但是第二次运行时,返回以下错误:
This code runs correctly the first time, but when run a second time, returns the following error:
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.pyx in h5py._objects.with_phil.wrapper (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_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2654)()
C:\ Users \ James \ AppData \ Local \ Enthought \ Canopy \ User \ lib \ site-packages \ h5py_hl \ group.py 在 setitem 中(自己,姓名,obj) 291其他: 292 ds = self.create_dataset(无,data = obj,dtype = base.guess_dtype(obj)) -> 293 h5o.link(ds.id,self.id,名称,lcpl = lcpl) 294 295 @with_phil
C:\Users\James\AppData\Local\Enthought\Canopy\User\lib\site-packages\h5py_hl\group.py in setitem(self, name, obj) 291 else: 292 ds = self.create_dataset(None, data=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.pyx in h5py._objects.with_phil.wrapper (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_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2654)()
h5py \ h5o.pyx (C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py \ h5o.c:3610)()
h5py\h5o.pyx in h5py.h5o.link (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py\h5o.c:3610)()
RuntimeError:无法创建链接(名称已经存在)
RuntimeError: Unable to create link (Name already exists)
%run"C:\ Users \ James \ Google Drive \ Python Scripts \ Python和 HDF5 \ Chapter3.py" -------------------------------------------------- ------------------------- IOError Traceback(最近的呼叫 最后)C:\ Users \ James \ Google Drive \ Python Scripts \ Python和 ()中的HDF5 \ Chapter3.py 从timeit导入timeit的4 5 ----> 6,其中h5py.File("testfile.hdf5","w-")为f: 7 arr = np.ones((5,2)) 8 f [我的数据集"] = arr
%run "C:\Users\James\Google Drive\Python Scripts\Python and HDF5\Chapter3.py" --------------------------------------------------------------------------- IOError Traceback (most recent call last) C:\Users\James\Google Drive\Python Scripts\Python and HDF5\Chapter3.py in () 4 from timeit import timeit 5 ----> 6 with h5py.File("testfile.hdf5", "w-") as f: 7 arr = np.ones((5,2)) 8 f["my dataset"] = arr
C:\ Users \ James \ AppData \ Local \ Enthought \ Canopy \ User \ lib \ site-packages \ h5py_hl \ files.py 在 init (自身,名称,模式,驱动程序,libver,userblock_size,swmr, ** kwds) 270 271 fapl = make_fapl(驱动程序,libver,** kwds) -> 272 fid = make_fid(名称,模式,userblock_size,fapl,swmr = swmr) 273 274,如果swmr_support:
C:\Users\James\AppData\Local\Enthought\Canopy\User\lib\site-packages\h5py_hl\files.py in init(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 if swmr_support:
C:\ Users \ James \ AppData \ Local \ Enthought \ Canopy \ User \ lib \ site-packages \ h5py_hl \ files.py 在make_fid中(名称,模式,userblock_size,fapl,fcpl,swmr) 94 fid = h5f.open(名称,h5f.ACC_RDWR,fapl = fapl) ['w-','x']中的95 elif模式: ---> 96 fid = h5f.create(名称,h5f.ACC_EXCL,fapl = fapl,fcpl = fcpl) 97 Elif模式=='w': 98 fid = h5f.create(名称,h5f.ACC_TRUNC,fapl = fapl,fcpl = fcpl)
C:\Users\James\AppData\Local\Enthought\Canopy\User\lib\site-packages\h5py_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr) 94 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl) 95 elif mode in ['w-', 'x']: ---> 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.pyx in h5py._objects.with_phil.wrapper (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_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2654)()
h5py \ h5f.pyx (C:\ pisi \ tmp \ h5py-2.6.0-2 \ work \ h5py-2.6.0 \ h5py \ h5f.c:2109)()
h5py\h5f.pyx in h5py.h5f.create (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py\h5f.c:2109)()
IOError:无法创建文件(无法打开文件:name = 'testfile.hdf5',错误号= 17,错误消息='文件存在',标志= 15,o_flags = 502)
IOError: Unable to create file (Unable to open file: name = 'testfile.hdf5', errno = 17, error message = 'file exists', flags = 15, o_flags = 502)
代码和错误在Canopy//Python 3.5中运行.我也在Spyder中运行它并收到了相同的结果.我也尝试使用
The code and error were run in Canopy // Python 3.5. I also ran it in Spyder and received the same result. I also tried using
没有成功.
推荐答案
当我使用 keras
(v2.2.2)中的"> HDF5Matrix
类.但是,当我有多个训练过程都需要访问磁盘上相同的HDF5
数据时,我找不到能够完全避免此错误的成熟解决方案.即使我将读取模式从默认的r+
修改为r
,也只有一个进程可以成功访问此HDF5
数据,而所有其他进程都将报告相同的错误.我放弃并使用了可行的解决方案,该解决方案保留HDF5
数据的多个副本,并为每个训练过程保留一个副本.
I encountered the exact same error message when I use HDF5Matrix
class in keras
(v2.2.2). However, I failed to find a mature solution to completely avoid this error when I have multiple training processes which all need to access the same HDF5
data on the disk. Only one process could successfully access this HDF5
data, while all others would report the same error, even though I modified the reading mode from the default r+
to r
. I gave up and used the workable solution that keeps multiple copies of HDF5
data and one copy for each training process.
这篇关于尝试打开h5py文件,返回errorno = 17,错误消息=“文件存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!