Python-docx: "package not found"

I have a doc.docx file at '/ var / code / oa'. I need to read it using python-docx. I am writing this:

from docx import Document
document = Document('/var/code/oa/doc.docx')

      

then you get an error .. PackageNotFoundError: package not found in '/var/code/oa/doc.docx'

why?

Thanks @soon. Oh, this is stupid. the cause is the file, it should be docx

. I just change the filename from doc

to docx

, this is not really a file docx

.

+3


source to share


1 answer


If there is nothing in your doc.docx, it will raise a PackageNotFoundError. Try putting something in it and do it again. Meanwhile, an invalid docx file will also throw this error. Tell me if it works.



+4


source







All Articles