docx.opc.exceptions.PackageNotFoundError: Package not found at '文件名.docx' 问题解决

编译源程序时,提示:docx.opc.exceptions.PackageNotFoundError: Package not found at '文件名.docx' 。html

源文件明明存在啊,难道是用的相对路径不能读取,因而换了绝对路径,结果仍是提示此错误。java

tpl = DocxTemplate("123.docx")this

究竟是什么缘由呢?spa

百度了一下,找到以下提示:【原文:https://www.javaear.com/question/47199300.html】code

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

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.ip

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

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.string

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

根据提示,插入上述代码后再次运行,查看显示的路径,便知道问题出在哪里了

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

原来程序编译运行的默认地址是notpad++的安装目录,因此致使找不到文件了。

因而,在CMD中从新进入源文件目录,编译并运行,结果顺利经过编译。

相关文章
相关标签/搜索