2

I'm trying to do anything considering word document using docx library in python. The problem is, whatever I import, I get error message about 'no attribute'. For eample - Document

from docx import Document

gives output

cannot import name Document

and any try to use Document ends with error

AttributeError: 'module' object has no attribute 'Document'

Any syntax seems to be correct. I'm using docx module version 0.2.4 .

Thanks for all help.

Misia Sowa
  • 23
  • 1
  • 4

3 Answers3

7

I had a similar problem. I had used pip install docx in my virtual environment. The fix was to pip uninstall docx and then pip install python-docx.

Smoke Liberator
  • 141
  • 1
  • 4
1

are you sure you properly installed docx? Because it seems it is not installed. You should try using pip or easy_install to install it properly.

http://python-docx.readthedocs.org/en/latest/user/install.html

For example, I never installed it and I get this following code error if I try to import it which is pretty much what you get :

Traceback (most recent call last):
  File "docx.py", line 1, in <module>
  from docx import Document
File "/Users/xxxx/Documents/Python/docx.py", line 1, in <module>
from docx import Document
ImportError: cannot import name Document
Clad Clad
  • 2,653
  • 1
  • 20
  • 32
1

from official documentation

python-docx versions 0.3.0 and later are not API-compatible with prior versions.

so, try to update package or use old api

go1dshtein
  • 315
  • 1
  • 2