.h5 file format does not close properly import h5py #added
hf = h5py.File('../images.h5', 'w') #added
hf.close() #added

h5_file = tables.open_file("images.h5", mode="w")


I also tried: 

h5py.File.close(hf)


the error that pops up in both cases is:

ValueError: The file 'restricted_images.h5' is already opened.  Please close it before reopening in write mode.


I've also tried:

if isinstance(obj, h5py.File):   # Just HDF5 files
    obj.close()


while 

In[]: hf
Out[]: &lt;Closed HDF5 file&gt; 


, the file is not closed yet.
You may want to use something like the following snippet:

with h5py.File("some_path.h5") as f:
   f["data1"] = some_data

import h5py #added
with h5py.File('../images.h5', 'w') as f:    
    h5_file = tables.open_file("images.h5", mode="w")
    # do what ever you want to do, it will be closed by itself.