partially initialized module 'h5py' has no attribute 'File' (most likely due to a circular import)

问题描述:
代码可以在jupyterlab中运行,但是不能在vscode等编辑器中运行,运行之后如下报错:
AttributeError: partially initialized module 'h5py' has no attribute 'File' (most likely due to a circular import)

import pandas as pd
import h5py
import matplotlib.pyplot as plt

with h5py.File(r"Data_01_04_28.h5", "r", swmr=True) as f:
###报错
AttributeError: partially initialized module 'h5py' has no attribute 'File' (most likely due to a circular import)


解决问题:
一开始以为"most likely due to a circular import"是因为代码中有循环所导致的vscode无法运行。

删除with结构后问题还是没有解决。然后以为是vscode配置的问题,但是anaconda内的vscode也无法运行此脚本。

最后发现是脚本命名(h5py.py)的问题。最后改一个名字就解决了!!!

脚本命名最好还是不要和库的名字相同,不然容易出问题。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容