为什么在导入docx时出现ModuleNotFoundError?

时间:2019-08-13 01:49:34

标签: python ms-word python-docx

我正在尝试从docx导入文档,但是发生了ModuleNotFoundError。

from docx import Document

# just for testing:
doc = Document()

运行此命令时,我得到以下输出:

Traceback (most recent call last):
  File "C:/Users/finnm/PycharmProjects/MesseMahlzeiten/TestScipt.py", line 1, in <module>
    from docx import Document
ModuleNotFoundError: No module named 'docx'

由于这可能会有所帮助,因此我向您展示了哪些pip安装输出:

C:\Users\finnm>pip install python-docx
Collecting python-docx
  Using cached https://files.pythonhosted.org/packages/e4/83/c66a1934ed5ed8ab1dbb9931f1779079f8bca0f6bbc5793c06c4b5e7d671/python-docx-0.8.10.tar.gz
Requirement already satisfied: lxml>=2.3.2 in c:\users\finnm\appdata\local\programs\python\python36\lib\site-packages (from python-docx) (4.4.1)
Installing collected packages: python-docx
  Running setup.py install for python-docx ... done
Successfully installed python-docx-0.8.10

1 个答案:

答案 0 :(得分:1)

已解决

我能够通过在脚本中实际执行pip安装来pip安装python-docx。

此问题的答案: Installing python module within code


感谢大家的帮助。