When import docx in python3.3 I have error ImportError: No module named 'exceptions'

柔情痞子 提交于 2019-11-29 00:51:09
Arun

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/

  1. Uninstall docx module with pip uninstall docx
  2. Download python_docx-0.8.6-py2.py3-none-any.whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/
  3. 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.

copied from

某某某

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

Dmitry

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!