我遇到有关 h5 文件的问题。每当我尝试加载它时,我都会收到此错误:
OSError: Can't read data (can't open directory: /opt/conda/envs/AE4353/lib/hdf5/plugin)
我可以毫无问题地读取文件,我提供了正确的路径,并且安装了我需要的一切。但是,当我尝试运行如下所示的简单代码时,我收到上面的错误。
def load_h5_file(h5_file_path):
with h5py.File(h5_file_path, "r") as file:
images = file["images"][:]
targets = file["targets"][:]
Images = torch.tensor(images)
Targets = torch.tensor(targets)
return Images, Targets
load_h5_file(h5_file_path)
考虑到我尝试安装插件的错误,但收到此错误:
(AE4353_user_env) vscode ➜ /workspaces/AE4353-Y24 (main) $ conda install -c conda-forge hdf5-plugin
Channels:
- conda-forge
- defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- hdf5-plugin
Current channels:
- https://conda.anaconda.org/conda-forge
- defaults
To search for alternate channels that may provide the conda package you're
looking for, navigate to https://anaconda.org and use the search bar at the top of the page.
所以我进入终端并尝试安装特定的插件,收到以下消息:
Requirement already satisfied: h5py[hdf5plugin] in /home/kibangadas/.local/lib/python3.8/site-packages (3.11.0)
WARNING: h5py 3.11.0 does not provide the extra 'hdf5plugin'
Requirement already satisfied: numpy>=1.17.3 in /home/kibangadas/.local/lib/python3.8/site-packages (from h5py[hdf5plugin]) (1.24.4)
后来我尝试单独安装hdf5插件,实际上下载并安装了它:
Collecting hdf5plugin
Downloading hdf5plugin-5.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.6 MB)
|████████████████████████████████| 45.6 MB 14.1 MB/s
Requirement already satisfied: h5py>=3.0.0 in /home/kibangadas/.local/lib/python3.8/site-packages (from hdf5plugin) (3.11.0)
Requirement already satisfied: numpy>=1.17.3 in /home/kibangadas/.local/lib/python3.8/site-packages (from h5py>=3.0.0->hdf5plugin) (1.24.4)
Installing collected packages: hdf5plugin
Successfully installed hdf5plugin-5.0.0
但最终我在 vscode 上不断遇到同样的错误,有什么想法可以解决这个问题吗?
因为插件不是用conda安装的,而是用pip安装的,但是你在conda文件夹“/opt/conda/envs”中搜索它,你可以尝试
import hdf5plugin