Docx库不识别Document方法
我正在尝试使用docx这个库,但出现了这个错误:
AttributeError: 'module' object has no attribute 'Document'
这是我的代码:
import docx
document = docx.Document('file.docx')
发生了什么事?我在其他电脑上已经用过这个文档了。我是通过pip安装的docx库:
pip install docx
1 个回答
12
你把包 docx
和包 python-docx
搞混了。
pip install python-docx
>>> import docx
>>> docx.Document
<class 'docx.api.Document'>
不过你说得对,这里命名确实有点问题。