zoukankan      html  css  js  c++  java
  • 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中重新进入源文件目录,编译并运行,结果顺利通过编译。

  • 相关阅读:
    IntlliJ IDEA 注册码获取或离线破解
    selenium元素定位
    appium元素定位
    django模型之meta使用
    django 之admin使用
    django之models模块使用
    Django的httprequest对象和httpresponse对象
    parameterized之unittest参数化
    HTMLTestRunner不生成报告
    collections之python基本应用
  • 原文地址:https://www.cnblogs.com/imustun/p/11225178.html
Copyright © 2011-2022 走看看