python导入PPT文件出错

使用python-pptx类库出错

我的python版本为3.10,下载的python-pptx类库的版本为0.6.21

代码为:

from pptx import Presentation
file_name=r'data/page.pptx'
prs = Presentation(file_name)
for slide in prs.slide:
    print(slide)

img

img

我想知道该下的类库都下了,代码也一样,文件地址也没错,那到底是为什么不能运行
import collections 
import collections.abc
from pptx import Presentation

Container=collections.abc.Container
AttributeError: module 'collections' has no attribute 'abc'
AttributeError:模块“collections”没有属性“abc”

解决方法是导入模块集合和集合。导入pptx前的abc,例:
import collections
import collections.abc
from pptx import Presentation


from pptx import Presentation # 导入演示文稿模块
prs = Presentation() # 创建一个演示文稿对象,同时也会创建一个空白文稿
prs.save('实例.pptx') #  保存演示文稿

希望对你有所帮助