解决:docx.opc.exceptions.PackageNotFoundError: Package not found at ‘xxx’

解决:docx.opc.exceptions.PackageNotFoundError: Package not found at ‘xxx’



文章目录

  • 解决:docx.opc.exceptions.PackageNotFoundError: Package not found at ‘xxx’
    • 背景
    • 报错问题
    • 报错翻译
    • 报错位置代码
    • 报错原因
    • 解决方法
      • 今天的分享就到此结束了



背景

在使用之前的代码时,报错:
Traceback (most recent call last):
File , line 1, in
file=docx.Document(“C:/Users/Administrator/Desktop/选择/add.doc”)
docx.opc.exceptions.PackageNotFoundError: Package not found at ‘xxx’



报错问题

Traceback (most recent call last): File , line 1, in  file=docx.Document("C:/Users/Administrator/Desktop/选择/add.doc") docx.opc.exceptions.PackageNotFoundError: Package not found at ‘xxx’

报错截图如下:

在这里插入图片描述



报错翻译

主要报错信息内容翻译如下所示:

Traceback (most recent call last): File , line 1, in  file=docx.Document("C:/Users/Administrator/Desktop/选择/add.doc") docx.opc.exceptions.PackageNotFoundError: Package not found at ‘xxx’

翻译:

回溯(最近一次调用最后一次): file=docx.Document("C:/Users/Administrator/Desktop/选择/add.doc")中的文件 “”,第 1 行 错误:未找到 rarfile 的匹配发行版


报错位置代码


...
import docx
file=docx.Document("C:/Users/Administrator/Desktop/选择/add.doc") 
...


报错原因

经过查阅资料,发现是使用docx.Document()读取文件的时候,支持读取 .docx 文件,不支持读取 .doc 文件,不是 .docx 需要转换成 .docx。

小伙伴们按下面的解决方法即可解决!!!



解决方法

要解决这个错误,需要使用wps打开文件另存为docx,才可以解决此问题。

正确的代码是:


...
import docx 
file=docx.Document("C:/Users/Administrator/Desktop/选择/add.docx") 
for para in doc.paragraphs:print(para.text)
...


今天的分享就到此结束了

欢迎点赞评论关注三连

在这里插入图片描述