• 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 FilesNotepad++456.docx

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

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

  • 相关阅读:
    falsh developer 快捷键
    FlashDevelop安装配置
    EditPlus保存时不生成bak文件(转)
    微信oauth2验证
    通过TortoiseSVN checkout的文件前面没有“状态标识”
    CSS3 Media Query 响应式媒体查询
    回车事件、键盘事件
    shiro登录密码加密
    mybatis常用类起别名
    shiro(四)项目开发中的配置、
  • 原文地址:https://www.cnblogs.com/imustun/p/11225178.html
Copyright © 2020-2023  润新知