Python docx 模块 ModuleNotFoundError

Python docx module ModuleNotFoundError

我是 windows 7 用户,使用 MS-Office 2016 和 python 3.6.
最近发现可以用python写word文档。 我看了 how to do that 我安装了 docx 模块:

pip install docx

但每当我尝试导入 docx 模块时,我都会收到此错误:

>>> from docx import Document
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Huzefa\AppData\Local\Programs\Py
in <module>
    from exceptions import PendingDeprecationWarn
ModuleNotFoundError: No module named 'exceptions'

我什至试过这个但它不会工作:

pip install exceptions

我收到这个错误:

ERROR: Could not find a version that satisfies the requirement exceptions (from versions: none)
ERROR: No matching distribution found for exceptions

我认为这可能是因为 docx 是一个 python-2 模块,但事实并非如此。我发现了 here

所以有人可以告诉我我做错了什么吗?

我建议你可以这样试试 -

$ pip install --pre python-docx

或者你也可以试试 sudo 命令 -

$ sudo pip install --pre python-docx

之后尝试 -

from docx import Document

从这里你可以找到[https://python-docx.readthedocs.io/en/latest/user/install.html][1]

尝试使用:

pip install python-docx

对我有用!