我收到了一个带有以下代码的ipython笔记本文件,我试图通过Jupyter执行它。
import docx;
from django.utils.encoding import smart_text;
doc = docx.Document('test_file.docx')
我得到以下追溯
---------------------------------------------------------------------------
PackageNotFoundError Traceback (most recent call last)
<ipython-input-8-2ff3b55810a7> in <module>()
1 import docx;
2 from django.utils.encoding import smart_text;
----> 3 doc = docx.Document('test_file.docx')
4 statements = [para.text.strip() for para in doc.paragraphs
5 if para.text.strip() != '']
C:\Program Files (x86)\Anaconda2\lib\site-packages\docx\api.pyc in Document(docx)
23 """
24 docx = _default_docx_path() if docx is None else docx
---> 25 document_part = Package.open(docx).main_document_part
26 if document_part.content_type != CT.WML_DOCUMENT_MAIN:
27 tmpl = "file '%s' is not a Word file, content type is '%s'"
C:\Program Files (x86)\Anaconda2\lib\site-packages\docx\opc\package.pyc in open(cls, pkg_file)
114 *pkg_file*.
115 """
--> 116 pkg_reader = PackageReader.from_file(pkg_file)
117 package = cls()
118 Unmarshaller.unmarshal(pkg_reader, package, PartFactory)
C:\Program Files (x86)\Anaconda2\lib\site-packages\docx\opc\pkgreader.pyc in from_file(pkg_file)
30 Return a |PackageReader| instance loaded with contents of *pkg_file*.
31 """
---> 32 phys_reader = PhysPkgReader(pkg_file)
33 content_types = _ContentTypeMap.from_xml(phys_reader.content_types_xml)
34 pkg_srels = PackageReader._srels_for(phys_reader, PACKAGE_URI)
C:\Program Files (x86)\Anaconda2\lib\site-packages\docx\opc\phys_pkg.pyc in __new__(cls, pkg_file)
29 else:
30 raise PackageNotFoundError(
---> 31 "Package not found at '%s'" % pkg_file
32 )
33 else: # assume it's a stream and pass it to Zip reader to sort out
PackageNotFoundError: Package not found at 'test_file.docx'
我最近卸载了docx
并重新安装了python-docx
,并想知道这是否相关,或者这是一个单独的问题?