python-pptx: AttributeError: module 'collections' has no attribute 'abc'
I just created a simple test.py file
from pptx import Presentation prs = Presentation()
but when I run it I get
`Traceback (most recent call last): File “C:\Python\lib\site-packages\pptx\compat_init_.py”, line 10, in <module> Container = collections.abc.Container AttributeError: module ‘collections’ has no attribute ‘abc’
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “D:\Docs\mycompany\Code\Python\Excel\test.py”, line 1, in <module> from pptx import Presentation File “C:\Python\lib\site-packages\pptx_init_.py”, line 14, in <module> from pptx.api import Presentation # noqa File “C:\Python\lib\site-packages\pptx\api.py”, line 15, in <module> from .package import Package File “C:\Python\lib\site-packages\pptx\package.py”, line 6, in <module> from pptx.opc.package import OpcPackage File “C:\Python\lib\site-packages\pptx\opc\package.py”, line 11, in <module> from pptx.compat import is_string, Mapping File “C:\Python\lib\site-packages\pptx\compat_init_.py”, line 14, in <module> Container = collections.Container AttributeError: module ‘collections’ has no attribute ‘Container’
Process finished with exit code 1`
Any idea why?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (7 by maintainers)
@dejudicibus yes, I think that’s the right workaround until we fix this, to import
collections.abc
beforepptx
After
import collections.abc
, thecollections
module will have a.abc
attribute and the Python2/3 machinery inpython-pptx
should work properly.It looks like Python 3.10 is happy if you do both imports