简体   繁体   中英

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.

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:

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

If you already installed docx uninstall docx using the commend,

pip uninstall docx

Reinstall the Python-docx

pip uninstall python-docx

pip install python-docx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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