Search code examples
pythonmacospython-2.7importerrorpython-docx

Unable to install python-docx (MacOS)


I am trying to install docx package. but getting the following ImportError:

ImportError: cannot import name Document

So as suggested here, I tried :

pip install python-docx but getting the following error (python version: 2.7.15)

..
..
..

    creating build/lib/docx/templates
    copying docx/templates/default-header.xml -> build/lib/docx/templates
    copying docx/templates/default-settings.xml -> build/lib/docx/templates
    copying docx/templates/default-footer.xml -> build/lib/docx/templates
    error: can't copy 'docx/templates/default-docx-template': doesn't exist or not a regular file 
    Command 

 /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import  

setuptools,tokenize;__file__='/private/var/folders/0c/v_yb4q7n2h3fg94rlfrr165r0000gn/T/pip-build-ks26RP/python-docx/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n',  

'\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/0c/v_yb4q7n2h3fg94rlfrr165r0000gn/T/pip-1SQvtb-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/0c/v_yb4q7n2h3fg94rlfrr165r0000gn/T/pip-build-ks26RP/python-docx/

Solution

  • There was a problem installing python-docx in certain environments in the recently released v0.8.9. Installing v0.8.10 should rectify that for most users. If installation still fails (on certain Linux versions), updating setuptools has been reported to fix it:

    $ pip install -U setuptools