How to fix the bug "ModuleNotFoundError: No module named 'exceptions'" when importing docx?

How to fix the bug "ModuleNotFoundError: No module named 'exceptions'" when importing docx?

我在这里找不到解决方案 "ansewered",所以我会 post 我发现的错误和我在这里制定的解决方案以及对我有帮助的链接。

问题是: 当我导入 docx

import docx 

我遇到了错误:

import docx
Traceback (most recent call last):

  File "<ipython-input-3-326e089686b3>", line 1, in <module>
    import docx

  File "C:\Users\T722696\AppData\Roaming\Python\Python37\site-packages\docx.py", line 30, in <module>
    from exceptions import PendingDeprecationWarning

ModuleNotFoundError: No module named 'exceptions'

我找到了这个解决方案 here, but it was not marked as solution. So I'm marking this as solution and giving the right credit to @Dmtry and do @dsh 由于docx不"yet"兼容Python 3.7,解决方法是在使用Python 3.7时更改docx本身:

一步一步:

1) 打开docx.py

2) 你会发现:

row | code

25  | try:
26  | from PIL.ExifTags import TAGS
27  | except ImportError:
28  |    TAGS = {}
29  |
30  | from exceptions import PendingDeprecationWarning

3) 您必须删除第 30 行并插入以下内容:

try:
    from exceptions import PendingDeprecationWarning
except ImportError:
    pass

4) 这应该可以解决您的问题。