简体   繁体   中英

h5py IOError: unable to open file

For some strange reason, h5py is unable to find an input file. It consistently throws this error unless the input file is in the same directory as the module that's attempting to open the file. This is strange because it used to work fine a while back:

infile = h5py.File("~/Dropbox/premalstuff/r/data/daily-mrgshrgpd.h5",'r')

and an excerpt from the IOError:

IOError: Unable to open file (Unable to open file: name = '~/dropbox/premalstuff/r/data/daily-mrgshrgpd.h5', errno = 2, error message = 'no such file or directory', flags = 0, o_flags = 0) 

Directory listing from the relevant directory: 在此处输入图片说明

I see that h5py changes "Dropbox" to "dropbox" ...but why? Any help is appreciated.

if you want to use ~/ path, use os.path.expanduser()

import os

your_path=os.path.expanduser('~/Dropbox/premalstuff/r/data/daily-mrgshrgpd.h5')
infile = h5py.File(your_path,'r')

Or use absolute path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM