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

吃可爱长大的小学妹 提交于 2019-11-26 12:45:48

问题


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)?


回答1:


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/




回答2:


  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...



回答3:


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




回答4:


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




回答5:


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



回答6:


I had the same problem, but pip install python-docx worked for me, I'm using python 3.7.1



来源:https://stackoverflow.com/questions/22765313/when-import-docx-in-python3-3-i-have-error-importerror-no-module-named-excepti

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