Misia Sowa
Misia Sowa

Reputation: 23

Docx missing attributes

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.

Upvotes: 2

Views: 6139

Answers (3)

Smoke Liberator
Smoke Liberator

Reputation: 141

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.

Upvotes: 7

go1dshtein
go1dshtein

Reputation: 315

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

Upvotes: 1

Clad Clad
Clad Clad

Reputation: 2781

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

Upvotes: 1

Related Questions