我有以下代码片段从.tzg文件中提取图像:
def read_raw_from_tar(tar_fn, fn):
with tarfile.open(tar_fn) as f:
m = f.getmember(fn)
return f.extractfile(m).read()
raw_bytes = read_raw_from_tar("102flowers.tgz", "jpg/image_00001.jpg")
在jupyter环境中执行此代码时,它将返回以下错误:
~\Anaconda3\envs\AML\lib\tarfile.py in open(cls, name, mode, fileobj, bufsize, **kwargs)
1576 fileobj.seek(saved_pos)
1577 continue
-> 1578 raise ReadError("file could not be opened successfully")
1579
1580 elif ":" in mode:
ReadError: file could not be opened successfully
有趣的是,当我在Coursera的环境中执行所有操作时,上面的代码段有效。
我该怎么做才能调试此问题?