0

I'm trying to import Document from docx but with this ModuleNotFoundError occures.

from docx import Document

# just for testing:
doc = Document()

When running this I am getting folowing output:

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'

Since it may could be helpful I show you what pip-installation outputs:

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
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
FinnK
  • 210
  • 4
  • 10
  • 1
    Are you sure you're running the same Python version as `pip`? – iBug Aug 13 '19 at 01:53
  • I already thought about that. I'm pretty sure I have just one installed but is there a way to ensure this? – FinnK Aug 13 '19 at 01:57
  • Maybe you have two Pythons. Check versions `pip -V` and `python -V`. You can also install using `python -m pip install ...` to make sure it install in correct Python. – furas Aug 13 '19 at 02:02
  • Also worth double-checking which python interpreter you're using for your pycharm: https://www.jetbrains.com/help/idea/configuring-local-python-interpreters.html – PeptideWitch Aug 13 '19 at 02:05
  • Tried all your suggestion.... pip is installed for python version 3.6, python displays 3.6.4 (should be the same, shouldn't it?). PyCharm is also using python 3.6. Nothing confusing to me at this. – FinnK Aug 13 '19 at 02:16
  • try running - import pip...pip.main(['install','python-docx']) from within the python shell to make sure you're using the proper pip for python version/interpreter you're using – Derek Eden Aug 13 '19 at 02:26
  • Doing this I'm getting: AttributeError: module 'pip' has no attribute 'main' ... – FinnK Aug 13 '19 at 11:40
  • there's some discussion on this issue here- https://stackoverflow.com/questions/49839610/attributeerror-module-pip-has-no-attribute-main I think you'll be able to get the command to work if you check here..some versions have main in different places – Derek Eden Aug 13 '19 at 12:26
  • Actually, looks like you have already figured that out :) – Derek Eden Aug 13 '19 at 12:27

1 Answers1

1

Solved

I was able to pip install python-docx by doing pip-installation actually inside my script.

This question answers to it: Installing python module within code


Thanks to everyone for helping me.

FinnK
  • 210
  • 4
  • 10