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

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

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

tpl = DocxTemplate("123.docx")

到底是什么原因呢?

百度了一下,找到如下提示:【原文: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.

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

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

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

于是,在CMD中重新进入源文件目录,编译并运行,结果顺利通过编译。

转载于:https://www.cnblogs.com/imustun/p/11225178.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值