docx.opc.exceptions.PackageNotFoundError: Package not found at 'file name .docx' problem-solving

When compiling source code, tips: docx.opc.exceptions.PackageNotFoundError: Package not found at 'file name .docx'.

Source file obviously exists ah, is it can not be read with a relative path, so for an absolute path, the result was prompt this error.

tpl = DocxTemplate("123.docx")

what is the reason behind the scene?

Baidu, I found the following prompt: [sic: https: //www.javaear.com/question/47199300.html]

This error simply means there is no .docx file at the location you specified.

Since you specified a relative path, the actual path used is determined by adding 'TestDir/dir2/doc22.docx' to the current working directory Python is using at run time.

You can discover the path being used with this short code snippet:

import os
print(os.path.abspath('TestDir/dir2/doc22.docx')

I expect you'll find that it prints out a path that does not exist, and that you'll need to modify the path string you give it to point to the right place.

Worst case, you can specify an absolute path, like /home/ch_dmitriy/Documents/Projects/Tutorials/TestDir/dir2/doc22.docx.

When prompted, insert the above code is run again to see the display of the path, we will know where the problem of

C:\Program Files\Notepad++\456.docx

The default address of the original program is compiled to run notpad ++ installation directory, so the cause can not find the files.

Then, re-enter CMD in the source file directory, compile and run the results successfully compile.

Guess you like

Origin www.cnblogs.com/imustun/p/11225178.html