Aditya Gupta
Aditya Gupta

Reputation: 157

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/

Upvotes: 5

Views: 3122

Answers (4)

nonoti
nonoti

Reputation: 1

Updating setup tools worked for me to.

I did a:

sudo easy_install -U setuptools

Then installed it again and it worked fine.

Upvotes: 0

scanny
scanny

Reputation: 28893

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

Upvotes: 3

Jamie Lindsey
Jamie Lindsey

Reputation: 993

If you are trying to install packages with pip you need to use sudo unless you are installing to a user directory. So it would be;

sudo pip install python-docx

You could also download the package from pypi untar it, cd into untared directory and run;

sudo python setup.py install

Updating setuptools to latest version may also be needed.

Upvotes: 0

arryph
arryph

Reputation: 2825

For python2.7, pip installer downloads source for python-docx which requires to be complied, c++ build tools are required for the compilation process. xcode command line tools provides required libraries for c++ sources to be compiled. To install xcode command line tools, use following command:

xcode-select --install

After xcode command line tools, use pip install python-docx again, this time compilation process should complete without any error and you will have python-docx installed on your system.

Upvotes: 0

Related Questions