program story

python3.3에서 docx를 가져올 때 ImportError : No module named 'exceptions'오류가 있습니다.

inputbox 2020. 12. 29. 07:04
반응형

python3.3에서 docx를 가져올 때 ImportError : No module named 'exceptions'오류가 있습니다.


가져올 때 docx다음 오류가 발생합니다.

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

이 오류 ( python3.3, docx 0.2.4) 를 수정하는 방법은 무엇입니까?


파이썬 3x를 사용하는 경우 pip install docx대신 하지 마십시오.

pip install python-docx 

파이썬 3x와 호환됩니다.

공식 문서 : https://pypi.org/project/python-docx/


  1. 다음을 사용하여 docx 모듈 제거 pip uninstall docx
  2. http://www.lfd.uci.edu/~gohlke/pythonlibs/python_docx-0.8.6-py2.py3-none-any.whl 에서 파일 다운로드
  3. pip install python_docx-0.8.6-py2.py3-none-any.whldocx를 다시 설치하려면 실행하십시오 . 이것은 위의 가져 오기 오류를 원활하게 해결했습니다. 솔루션을 제공하기 위해 ...

Python 3에서 예외 모듈이 제거되고 모든 표준 예외가 내장 모듈로 이동되었습니다. 따라서 표준 예외를 명시 적으로 가져올 필요가 더 이상 없습니다.

복사


이전 의견에서 언급했듯이 문제는 docx 모듈이 Python 3과 호환되지 않는다는 것입니다. github의 pull-request에서 수정되었습니다. https://github.com/mikemaccana/python-docx/pull/67

이제 예외가 기본 제공되므로 해결 방법은 예외를 가져 오지 않는 것입니다.

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

당신은 설치 할 수있다 docx, 없다python-docx

설치를 위해 이것을 볼 수 있습니다. python-docx

http://python-docx.readthedocs.io/en/latest/user/install.html#install

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

반응형