I am currently writing a python 3 program that parses through certain docx files and extracts the text and images from them. I have been trying to use docx but it will not import into my program. I have installed lxml, Pillow, and python-docx yet it does not import. When I try to use python-docx from the terminal I cannot use example-extracttext.py or example-makedocument.py which brings me to believe that the installation didn't run properly. Is there a way I can check if this installed correctly or is there a way to get this working properly so I can import it into my project? I am on Ubuntu 13.10.
-
1how are you installing? Using `pip`? It sounds offhand like a multiple-Python-environment problem, where you are installing into one and executing in another. – scanny Feb 10 '14 at 01:43
-
I am installing using pip, which did not work. I also tried to install manually by downloading the project and using python3 setup.py install. Neither worked. – thehoule64 Feb 10 '14 at 02:03
3 Answers
I recommend you try the latest version of python-docx which is installed like this:
$ pip install python-docx
Documentation is available here: http://python-docx.readthedocs.org/
Installation should result in a message that looks successful. It's possible you'll need to install using sudo to temporarily assume root privileges:
$ sudo pip install python-docx
After installation you should be able to do the following in the Python interpreter:
>>> from docx import Document
>>>
If instead you get something like this, the install didn't go properly:
>>> from docx import Document
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named docx
As you can provide more feedback on your attempts I can elaborate the answer.
Note that after v0.2.x the python-docx package was rewritten. The API of v0.3.x+ is different as well as the package name and repository location. All further development will be on the new version. If you're just starting out with the package going with the latest is probably a good idea as the old one will just be receiving legacy support going forward.
Also, the Python 3 support was added with v0.3.0. Prior versions are not Python 3 compatible.

- 26,423
- 5
- 54
- 80
you can solve your import problem by first uninstalling the existant installation and then install it with pip3. solved my problem with this
pip uninstall python-docx
pip3 install python-docx

- 25
- 4
Use Command- sudo pip install --pre python-docx
for the latest version of python-docx.

- 107
- 1
- 3
-
Even though it appeared to be successfully installed, it isn't listed in my site-packages folder (I can't attach a screengrab in the comments) **Collecting python-docx Collecting lxml>=2.3.2 (from python-docx) Downloading https://files.pythonhosted.org/packages/5c/4c/...macosx_10_6_intel.macosx_10_9_intel....(8.8MB) 100% Installing collected packages: lxml, python-docx Successfully installed lxml-4.2.3 python-docx-0.8.6** Mac High sierra, python 3.7, Pycharm 2018. Could someone tell me why isn't it listed after successful install? Thanks. – Chris22 Jul 15 '18 at 06:07