Docx library does not recognize Document method

I am trying to use the docx library, but I am getting this error:

AttributeError: 'module' object has no attribute 'Document'

      

This is my code:

import docx
document = docx.Document('file.docx')

      

What's happening? I have already used the document on other computers. I installed the docx library using pip:

pip install docx

      

+3


source to share


1 answer


your confusing package docx

with package python-docx

.

pip install python-docx


>>> import docx
>>> docx.Document
<class 'docx.api.Document'>

      



But you're right, naming is a problem here.

+9


source







All Articles