我正在尝试使用 docx 库,但出现此错误:
AttributeError: 'module' object has no attribute 'Document'
这是我的代码:
import docx
document = docx.Document('file.docx')
发生了什么事?我已经在其他计算机上使用过文档。我使用 pip 安装了 docx 库:
pip install docx
最佳答案
你的混淆包 docx
与包 python-docx
。
pip install python-docx
>>> import docx
>>> docx.Document
<class 'docx.api.Document'>
但你是对的,这里的命名是个问题。
关于python - Docx 库无法识别文档方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25137612/