when I import docx
I have this error:
>File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docx-0.2.4-py3.3.egg/docx.py", line 30, in <module>
from exceptions import PendingDeprecationWarning
ImportError: No module named 'exceptions'
How to fix this error (python3.3
, docx 0.2.4
)?
If you are using python 3x don't do pip install docx
instead go for
pip install python-docx
it is compatible with python 3x
official Document: https://pypi.org/project/python-docx/
- Uninstall docx module with
pip uninstall docx
- Download
python_docx-0.8.6-py2.py3-none-any.whl
file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ - Run
pip install python_docx-0.8.6-py2.py3-none-any.whl
to reinstall docx. This solved the above import error smoothly for me. Just to provide a solution...
In Python 3 exceptions module was removed and all standard exceptions were moved to builtin module. Thus meaning that there is no more need to do explicit import of any standard exceptions.
You may be install docx
, not python-docx
You can see this for install python-docx
http://python-docx.readthedocs.io/en/latest/user/install.html#install
The problem, as was noted previously in comments, is the docx module was not compatible with Python 3. It was fixed in this pull-request on github: https://github.com/mikemaccana/python-docx/pull/67
Since the exception is now built-in, the solution is to not import it.
docx.py
@@ -27,7 +27,12 @@
except ImportError:
TAGS = {}
-from exceptions import PendingDeprecationWarning
+# Handle PendingDeprecationWarning causing an ImportError if using Python 3
+try:
+ from exceptions import PendingDeprecationWarning
+except ImportError:
+ pass
+
from warnings import warn
import logging
来源:https://stackoverflow.com/questions/22765313/when-import-docx-in-python3-3-i-have-error-importerror-no-module-named-excepti