1

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!

AcK
  • 2,063
  • 2
  • 20
  • 27
  • 1
    Is your file named `docx.py`? rename it to something else – Abdul Aziz Barkat Mar 03 '21 at 13:07
  • No based on the attached tutorial, it is actually creating a new file called 'CV.docx' https://www.youtube.com/watch?v=YU89CWaeO9M&list=PLwvrYc43l1MzSBvslCMVZGtLLaZTq3VTG&index=17&ab_channel=Amigoscode – NorthernFalcon Mar 03 '21 at 13:09
  • Not the file you want to save. The name of your **python** file / the file in which you write code. – Abdul Aziz Barkat Mar 03 '21 at 13:15
  • 1
    As mentioned by @AbdulAzizBarkat, you seem to be in this situation: https://stackoverflow.com/questions/6031584/importing-from-builtin-library-when-module-with-same-name-exists : you have a local file docx.py that "hides" the standard module docx – Demi-Lune Mar 03 '21 at 13:18
  • The file i was using was called my_app.py – NorthernFalcon Mar 03 '21 at 13:22

2 Answers2

0

I have no idea why, but I closed my terminal, reopened it, uninstalled everything in the same order, and reinstalled it and it worked.

0

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
Elango Sk
  • 51
  • 4