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中從新進入源文件目錄,編譯並運行,結果順利經過編譯。

相關文章
相關標籤/搜索