Python-docx: can't copy 'docx/templates/default-docx-template' on pip install python-docx

Created on 9 Jan 2019  路  20Comments  路  Source: python-openxml/python-docx

Hi, I'm not sure if this is the right place for posting this but, I've installed the package using pip install python-docx, and tried to execute the first tutorial. Then got this error:

"Package not found at '%s'" % pkg_file docx.opc.exceptions.PackageNotFoundError: Package not found at '/home/----/anaconda3/envs/myenv/lib/python3.6/site-packages/docx/templates/default-docx-template'

Then I went to the folder and there is no _default-docx-template_ folder. I checked here on GitHub and it's there.

Most helpful comment

UPDATE: Short answer is to update your setuptools:

$ pip install -U setuptools

Hmm, could be a problem with the MANIFEST.ini, that directory was just added on the last release which makes me suspect. I'll check it out here ...

All 20 comments

UPDATE: Short answer is to update your setuptools:

$ pip install -U setuptools

Hmm, could be a problem with the MANIFEST.ini, that directory was just added on the last release which makes me suspect. I'll check it out here ...

Ah, yes, good catch, it looks like there was a "*" in there where it shouldn't have been. I'll push a new release right away. Thanks for reporting this :)

Okay, should be fixed now with v0.8.9 available from PyPI. Thanks again for reporting. Please let me know how you go :)

It's a pleasure to help! Unfortunately the folder is still missing =(.
I'm using v0.8.7 as a work around and everything is working fine.

Hi @edivaldodelgado, apologies, I should have tested more thoroughly, the problem ran a little deeper than I thought, but works for me now on 0.8.10. I had to install with pip install python-docx==0.8.10 to get it to pick up from PyPI, but that was probably because I had uploaded it minutes before and I suppose pip caches or something. Let me know if it works for you.

Hi @scanny
I am still getting the same symptoms with my 0.8.10 install
error: can't copy 'docx/templates/default-docx-template': doesn't exist or not a regular file
I even tried downloading the source 0.8.10 tarball and running
python3 setup.py install
Still got the same result.
The docx/templates/default-docx-template does exist, but it is a folder.

Let me know if you would like any further troubleshooting carried out.

@RogueRaider your error is actually different from the original and I am unable to reproduce it. Please post the entire error message.

@scanny

As requested

(env) acacia@corsair:~/docx_generator/python-docx-0.8.10$ sudo python3 setup.py install
[sudo] password for acacia: 
running install
Checking .pth file support in /usr/local/lib/python3.5/dist-packages/
/usr/bin/python3 -E -c pass
TEST PASSED: /usr/local/lib/python3.5/dist-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing dependency_links to python_docx.egg-info/dependency_links.txt
writing requirements to python_docx.egg-info/requires.txt
writing top-level names to python_docx.egg-info/top_level.txt
writing python_docx.egg-info/PKG-INFO
reading manifest file 'python_docx.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'docs/.build'
warning: no previously-included files matching '.DS_Store' found anywhere in distribution
warning: no previously-included files matching '__pycache__' found anywhere in distribution
warning: no previously-included files matching '*.py[co]' found anywhere in distribution
writing manifest file 'python_docx.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
error: can't copy 'docx/templates/default-docx-template': doesn't exist or not a regular file
(env) acacia@corsair:~/docx_generator/python-docx-0.8.10$ 

@scanny Added the pip install output which seems to be more verbose

(env) acacia@corsair:~/docx_generator$ python3 -m pip install python-docx==0.8.10
Collecting python-docx==0.8.10
  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 /home/acacia/.local/lib/python3.5/site-packages (from python-docx==0.8.10) (4.3.0)
Building wheels for collected packages: python-docx
  Running setup.py bdist_wheel for python-docx ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-j6khlcmk/python-docx/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-03kqyixv --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/docx
  copying docx/settings.py -> build/lib/docx
  copying docx/document.py -> build/lib/docx
  copying docx/compat.py -> build/lib/docx
  copying docx/table.py -> build/lib/docx
  copying docx/shape.py -> build/lib/docx
  copying docx/exceptions.py -> build/lib/docx
  copying docx/__init__.py -> build/lib/docx
  copying docx/shared.py -> build/lib/docx
  copying docx/package.py -> build/lib/docx
  copying docx/section.py -> build/lib/docx
  copying docx/api.py -> build/lib/docx
  copying docx/blkcntnr.py -> build/lib/docx
  creating build/lib/docx/styles
  copying docx/styles/styles.py -> build/lib/docx/styles
  copying docx/styles/latent.py -> build/lib/docx/styles
  copying docx/styles/style.py -> build/lib/docx/styles
  copying docx/styles/__init__.py -> build/lib/docx/styles
  creating build/lib/docx/opc
  copying docx/opc/coreprops.py -> build/lib/docx/opc
  copying docx/opc/compat.py -> build/lib/docx/opc
  copying docx/opc/constants.py -> build/lib/docx/opc
  copying docx/opc/pkgreader.py -> build/lib/docx/opc
  copying docx/opc/exceptions.py -> build/lib/docx/opc
  copying docx/opc/pkgwriter.py -> build/lib/docx/opc
  copying docx/opc/phys_pkg.py -> build/lib/docx/opc
  copying docx/opc/packuri.py -> build/lib/docx/opc
  copying docx/opc/rel.py -> build/lib/docx/opc
  copying docx/opc/__init__.py -> build/lib/docx/opc
  copying docx/opc/shared.py -> build/lib/docx/opc
  copying docx/opc/spec.py -> build/lib/docx/opc
  copying docx/opc/package.py -> build/lib/docx/opc
  copying docx/opc/part.py -> build/lib/docx/opc
  copying docx/opc/oxml.py -> build/lib/docx/opc
  creating build/lib/docx/dml
  copying docx/dml/__init__.py -> build/lib/docx/dml
  copying docx/dml/color.py -> build/lib/docx/dml
  creating build/lib/docx/parts
  copying docx/parts/settings.py -> build/lib/docx/parts
  copying docx/parts/document.py -> build/lib/docx/parts
  copying docx/parts/numbering.py -> build/lib/docx/parts
  copying docx/parts/image.py -> build/lib/docx/parts
  copying docx/parts/styles.py -> build/lib/docx/parts
  copying docx/parts/hdrftr.py -> build/lib/docx/parts
  copying docx/parts/__init__.py -> build/lib/docx/parts
  copying docx/parts/story.py -> build/lib/docx/parts
  creating build/lib/docx/oxml
  copying docx/oxml/settings.py -> build/lib/docx/oxml
  copying docx/oxml/coreprops.py -> build/lib/docx/oxml
  copying docx/oxml/document.py -> build/lib/docx/oxml
  copying docx/oxml/numbering.py -> build/lib/docx/oxml
  copying docx/oxml/table.py -> build/lib/docx/oxml
  copying docx/oxml/shape.py -> build/lib/docx/oxml
  copying docx/oxml/exceptions.py -> build/lib/docx/oxml
  copying docx/oxml/styles.py -> build/lib/docx/oxml
  copying docx/oxml/simpletypes.py -> build/lib/docx/oxml
  copying docx/oxml/ns.py -> build/lib/docx/oxml
  copying docx/oxml/__init__.py -> build/lib/docx/oxml
  copying docx/oxml/shared.py -> build/lib/docx/oxml
  copying docx/oxml/section.py -> build/lib/docx/oxml
  copying docx/oxml/xmlchemy.py -> build/lib/docx/oxml
  creating build/lib/docx/text
  copying docx/text/paragraph.py -> build/lib/docx/text
  copying docx/text/__init__.py -> build/lib/docx/text
  copying docx/text/parfmt.py -> build/lib/docx/text
  copying docx/text/run.py -> build/lib/docx/text
  copying docx/text/font.py -> build/lib/docx/text
  copying docx/text/tabstops.py -> build/lib/docx/text
  creating build/lib/docx/enum
  copying docx/enum/table.py -> build/lib/docx/enum
  copying docx/enum/text.py -> build/lib/docx/enum
  copying docx/enum/shape.py -> build/lib/docx/enum
  copying docx/enum/style.py -> build/lib/docx/enum
  copying docx/enum/__init__.py -> build/lib/docx/enum
  copying docx/enum/base.py -> build/lib/docx/enum
  copying docx/enum/section.py -> build/lib/docx/enum
  copying docx/enum/dml.py -> build/lib/docx/enum
  creating build/lib/docx/image
  copying docx/image/image.py -> build/lib/docx/image
  copying docx/image/constants.py -> build/lib/docx/image
  copying docx/image/tiff.py -> build/lib/docx/image
  copying docx/image/exceptions.py -> build/lib/docx/image
  copying docx/image/png.py -> build/lib/docx/image
  copying docx/image/helpers.py -> build/lib/docx/image
  copying docx/image/__init__.py -> build/lib/docx/image
  copying docx/image/gif.py -> build/lib/docx/image
  copying docx/image/bmp.py -> build/lib/docx/image
  copying docx/image/jpeg.py -> build/lib/docx/image
  creating build/lib/docx/opc/parts
  copying docx/opc/parts/coreprops.py -> build/lib/docx/opc/parts
  copying docx/opc/parts/__init__.py -> build/lib/docx/opc/parts
  creating build/lib/docx/oxml/text
  copying docx/oxml/text/paragraph.py -> build/lib/docx/oxml/text
  copying docx/oxml/text/__init__.py -> build/lib/docx/oxml/text
  copying docx/oxml/text/parfmt.py -> build/lib/docx/oxml/text
  copying docx/oxml/text/run.py -> build/lib/docx/oxml/text
  copying docx/oxml/text/font.py -> build/lib/docx/oxml/text
  creating build/lib/docx/templates
  copying docx/templates/default-header.xml -> build/lib/docx/templates
  copying docx/templates/default.docx -> build/lib/docx/templates
  copying docx/templates/default-styles.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

  ----------------------------------------
  Failed building wheel for python-docx
  Running setup.py clean for python-docx
Failed to build python-docx
Installing collected packages: python-docx
  Running setup.py install for python-docx ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-j6khlcmk/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 /tmp/pip-record-dix9lty7/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/docx
    copying docx/settings.py -> build/lib/docx
    copying docx/document.py -> build/lib/docx
    copying docx/compat.py -> build/lib/docx
    copying docx/table.py -> build/lib/docx
    copying docx/shape.py -> build/lib/docx
    copying docx/exceptions.py -> build/lib/docx
    copying docx/__init__.py -> build/lib/docx
    copying docx/shared.py -> build/lib/docx
    copying docx/package.py -> build/lib/docx
    copying docx/section.py -> build/lib/docx
    copying docx/api.py -> build/lib/docx
    copying docx/blkcntnr.py -> build/lib/docx
    creating build/lib/docx/styles
    copying docx/styles/styles.py -> build/lib/docx/styles
    copying docx/styles/latent.py -> build/lib/docx/styles
    copying docx/styles/style.py -> build/lib/docx/styles
    copying docx/styles/__init__.py -> build/lib/docx/styles
    creating build/lib/docx/opc
    copying docx/opc/coreprops.py -> build/lib/docx/opc
    copying docx/opc/compat.py -> build/lib/docx/opc
    copying docx/opc/constants.py -> build/lib/docx/opc
    copying docx/opc/pkgreader.py -> build/lib/docx/opc
    copying docx/opc/exceptions.py -> build/lib/docx/opc
    copying docx/opc/pkgwriter.py -> build/lib/docx/opc
    copying docx/opc/phys_pkg.py -> build/lib/docx/opc
    copying docx/opc/packuri.py -> build/lib/docx/opc
    copying docx/opc/rel.py -> build/lib/docx/opc
    copying docx/opc/__init__.py -> build/lib/docx/opc
    copying docx/opc/shared.py -> build/lib/docx/opc
    copying docx/opc/spec.py -> build/lib/docx/opc
    copying docx/opc/package.py -> build/lib/docx/opc
    copying docx/opc/part.py -> build/lib/docx/opc
    copying docx/opc/oxml.py -> build/lib/docx/opc
    creating build/lib/docx/dml
    copying docx/dml/__init__.py -> build/lib/docx/dml
    copying docx/dml/color.py -> build/lib/docx/dml
    creating build/lib/docx/parts
    copying docx/parts/settings.py -> build/lib/docx/parts
    copying docx/parts/document.py -> build/lib/docx/parts
    copying docx/parts/numbering.py -> build/lib/docx/parts
    copying docx/parts/image.py -> build/lib/docx/parts
    copying docx/parts/styles.py -> build/lib/docx/parts
    copying docx/parts/hdrftr.py -> build/lib/docx/parts
    copying docx/parts/__init__.py -> build/lib/docx/parts
    copying docx/parts/story.py -> build/lib/docx/parts
    creating build/lib/docx/oxml
    copying docx/oxml/settings.py -> build/lib/docx/oxml
    copying docx/oxml/coreprops.py -> build/lib/docx/oxml
    copying docx/oxml/document.py -> build/lib/docx/oxml
    copying docx/oxml/numbering.py -> build/lib/docx/oxml
    copying docx/oxml/table.py -> build/lib/docx/oxml
    copying docx/oxml/shape.py -> build/lib/docx/oxml
    copying docx/oxml/exceptions.py -> build/lib/docx/oxml
    copying docx/oxml/styles.py -> build/lib/docx/oxml
    copying docx/oxml/simpletypes.py -> build/lib/docx/oxml
    copying docx/oxml/ns.py -> build/lib/docx/oxml
    copying docx/oxml/__init__.py -> build/lib/docx/oxml
    copying docx/oxml/shared.py -> build/lib/docx/oxml
    copying docx/oxml/section.py -> build/lib/docx/oxml
    copying docx/oxml/xmlchemy.py -> build/lib/docx/oxml
    creating build/lib/docx/text
    copying docx/text/paragraph.py -> build/lib/docx/text
    copying docx/text/__init__.py -> build/lib/docx/text
    copying docx/text/parfmt.py -> build/lib/docx/text
    copying docx/text/run.py -> build/lib/docx/text
    copying docx/text/font.py -> build/lib/docx/text
    copying docx/text/tabstops.py -> build/lib/docx/text
    creating build/lib/docx/enum
    copying docx/enum/table.py -> build/lib/docx/enum
    copying docx/enum/text.py -> build/lib/docx/enum
    copying docx/enum/shape.py -> build/lib/docx/enum
    copying docx/enum/style.py -> build/lib/docx/enum
    copying docx/enum/__init__.py -> build/lib/docx/enum
    copying docx/enum/base.py -> build/lib/docx/enum
    copying docx/enum/section.py -> build/lib/docx/enum
    copying docx/enum/dml.py -> build/lib/docx/enum
    creating build/lib/docx/image
    copying docx/image/image.py -> build/lib/docx/image
    copying docx/image/constants.py -> build/lib/docx/image
    copying docx/image/tiff.py -> build/lib/docx/image
    copying docx/image/exceptions.py -> build/lib/docx/image
    copying docx/image/png.py -> build/lib/docx/image
    copying docx/image/helpers.py -> build/lib/docx/image
    copying docx/image/__init__.py -> build/lib/docx/image
    copying docx/image/gif.py -> build/lib/docx/image
    copying docx/image/bmp.py -> build/lib/docx/image
    copying docx/image/jpeg.py -> build/lib/docx/image
    creating build/lib/docx/opc/parts
    copying docx/opc/parts/coreprops.py -> build/lib/docx/opc/parts
    copying docx/opc/parts/__init__.py -> build/lib/docx/opc/parts
    creating build/lib/docx/oxml/text
    copying docx/oxml/text/paragraph.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/__init__.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/parfmt.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/run.py -> build/lib/docx/oxml/text
    copying docx/oxml/text/font.py -> build/lib/docx/oxml/text
    creating build/lib/docx/templates
    copying docx/templates/default-header.xml -> build/lib/docx/templates
    copying docx/templates/default.docx -> build/lib/docx/templates
    copying docx/templates/default-styles.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 "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-j6khlcmk/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 /tmp/pip-record-dix9lty7/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-j6khlcmk/python-docx/
(env) acacia@corsair:~/docx_generator$ 

Hmm, interesting. Home come you don't just call pip from the command line like this?

$ pip install python-docx

I'll try and reproduce it using setup.py. I expect it has to do with that new directory in there not being a file, I'll see if I can suss out the magic incantation to get it to skip directories. Unfortunately the documentation on that sort of thing is a little hard to come by.

@RogueRaider Ok, I can't reproduce this with either of your commands. In any case, it shouldn't be this hard. Just use pip install python-docx and if that doesn't work let me know how it fails. There should be no reason I know of you have to add the python3 -m pip bit on the front (although I learn new things every day). Also make sure you have an up-to-date version of pip installed. Also make sure you've completely deleted the extracted tarballs so you're not inadvertently running something old. My trials did not attempt to copy/install default-docx-template, which makes me think maybe your extracts are mixed in with old versions or something. Wipe clean and try again directly with pip.

@RogueRaider Could you please provide setuptools version?

I was facing similar situation.

Failing on following setup

  • OS: Ubuntu 16.04
  • Python: 2.7.10 and 3.5.2
  • setuptools: 20.7.0

It worked on following setup

  • OS: MacOS
  • Python: 3.6.5
  • setuptools: 40.6.2

On ubuntu by updating setuptools pip install -U setuptools it worked.

@scanny
I have no idea about relationship between setuptools and this package but it may better to limit its version.

@K4zuki
Thank you for this input. Updating setuptools fixed my issue.
I was trying to install this on ubuntu 16.04. After having some issues with updating pip, I tried a fresh linux install of mint. Still the same problem. Then I tried installing on Windows and python-docx worked with no problems.

So I knew it was something to do with linux and possibly my local config. But following your suggestion I was able to successfully install the package :)

@scanny
Thanks for your help. Appreciate your time and efforts :)

@RogueRaider Grad to hear it worked for you 馃憤

Hello,
I have the same issue with version 0.8.9.
I don't have the issue with version 0.8.7.
I guess this commit https://github.com/python-openxml/python-docx/commit/ada86c3880f1b070ad6525201610866af4945865 broke the thing.

@titilambert Use versoin 0.8.10 and make sure your setuptools is up-to-date (v40.x or so).

@scanny python-docx==0.8.10 installation has missing default-docx-template directory. Is it intentional ?

I met the same problem when install python-docx==0.8.10. My environment is

  • setuptools: 50.3.2
  • ubuntu: 16.04
  • python: 3.6.8
  • pip3: 20.2.4

but it works when install python-docx 0.8.7.
Just report

This issue has been fixed with da75fcf01f7f322e846e2ac3e1936aedd766acc8 as far as I can tell, but somehow that hasn't made it way to the PyPI tarball. The PyPI tarball python-docx-0.8.10.tar.gz still has

PACKAGE_DATA = {'docx': ['templates/*']}

instead of

PACKAGE_DATA = {'docx': ['templates/*.xml', 'templates/*.docx']}

So my guess a stale version of the package has been uploaded to PyPI (since the v0.8.10 tag references da75fcf01f7f322e846e2ac3e1936aedd766acc8). @scanny could you release a new build of 0.8.10 to PyPI? Perhaps with a wheel as well?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tores76 picture Tores76  路  6Comments

floatc picture floatc  路  4Comments

kndidox picture kndidox  路  5Comments

achillis1 picture achillis1  路  5Comments

bendaojiu picture bendaojiu  路  5Comments