简体   繁体   English

使用 python-docx 时出现错误“找不到参考‘文档’”

[英]Error "Cannot find reference 'Document'" using python-docx

I'm following a tutorial online on how to import a docx file using Python 3.9.2.我正在网上关注如何使用 Python 3.9.2 导入 docx 文件的教程。

I've installed the following using terminal:我已经使用终端安装了以下内容:

python -m pip install --upgrade pip setuptools wheel
pip install python-docx

when I run pip list it shows:当我运行 pip 列表时,它显示:

Package     Version
----------- -------
lxml        4.6.2
pip         21.0.1
python-docx 0.8.10
setuptools  54.0.0
wheel       0.36.2

However, when I enter the following code:但是,当我输入以下代码时:

from docx import Document
document = Document()
document.save('CV.docx')

I get this error code:我得到这个错误代码:

"Cannot find reference 'Document' in 'docx.py'"

Thank you in advance!先感谢您!

I have no idea why, but I closed my terminal, reopened it, uninstalled everything in the same order, and reinstalled it and it worked.我不知道为什么,但我关闭了我的终端,重新打开它,以相同的顺序卸载了所有东西,然后重新安装它并且它工作了。

Reinstall the python-docx, Remove the docx and install python-docx重新安装 python-docx,删除 docx 并安装 python-docx

If you already installed docx uninstall docx using the commend,如果您已经使用推荐安装了 docx,请卸载 docx,

pip uninstall docx

Reinstall the Python-docx重新安装 Python-docx

pip uninstall python-docx

pip install python-docx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM