问题
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.
回答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
回答2:
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
.
回答3:
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
来源:https://stackoverflow.com/questions/24992092/docx-missing-attributes