---------------------------------------------------------------------------
PackageNotFoundError Traceback (most recent call last)
Cell In[1], line 30
27 new_prs.save(output_path)
29 # 使用示例
---> 30 keep_first_slide("原始文件.pptx", "仅第一页.pptx")
Cell In[1], line 5, in keep_first_slide(input_path, output_path)
3 def keep_first_slide(input_path, output_path):
4 # 打开原始PPT
----> 5 prs = Presentation(input_path)
7 # 创建新演示文稿
8 new_prs = Presentation()
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\api.py:31, in Presentation(pptx)
28 if pptx is None:
29 pptx = _default_pptx_path()
---> 31 presentation_part = Package.open(pptx).main_document_part
33 if not _is_pptx_package(presentation_part):
34 tmpl = "file '%s' is not a PowerPoint file, content type is '%s'"
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py:82, in OpcPackage.open(cls, pkg_file)
79 @classmethod
80 def open(cls, pkg_file: str | IO[bytes]) -> Self:
81 """Return an |OpcPackage| instance loaded with the contents of `pkg_file`."""
---> 82 return cls(pkg_file)._load()
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py:160, in OpcPackage._load(self)
158 def _load(self) -> Self:
159 """Return the package after loading all parts and relationships."""
--> 160 pkg_xml_rels, parts = _PackageLoader.load(self._pkg_file, cast("Package", self))
161 self._rels.load_from_xml(PACKAGE_URI, pkg_xml_rels, parts)
162 return self
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py:190, in _PackageLoader.load(cls, pkg_file, package)
177 @classmethod
178 def load(
179 cls, pkg_file: str | IO[bytes], package: Package
180 ) -> tuple[CT_Relationships, dict[PackURI, Part]]:
181 """Return (pkg_xml_rels, parts) pair resulting from loading `pkg_file`.
182
183 The returned `parts` value is a {partname: part} mapping with each part in the package
(...)
188 those relationships into its |_Relationships| object.
189 """
--> 190 return cls(pkg_file, package)._load()
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py:194, in _PackageLoader._load(self)
192 def _load(self) -> tuple[CT_Relationships, dict[PackURI, Part]]:
193 """Return (pkg_xml_rels, parts) pair resulting from loading pkg_file."""
--> 194 parts, xml_rels = self._parts, self._xml_rels
196 for partname, part in parts.items():
197 part.load_rels_from_xml(xml_rels[partname], parts)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\util.py:191, in lazyproperty.__get__(self, obj, type)
186 value = obj.__dict__.get(self._name)
187 if value is None:
188 # --- on first access, the __dict__ item will be absent. Evaluate fget()
189 # --- and store that value in the (otherwise unused) host-object
190 # --- __dict__ value of same name ('fget' nominally)
--> 191 value = self._fget(obj)
192 obj.__dict__[self._name] = value
193 return cast(_T, value)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py:222, in _PackageLoader._parts(self)
214 @lazyproperty
215 def _parts(self) -> dict[PackURI, Part]:
216 """dict {partname: Part} populated with parts loading from package.
217
218 Among other duties, this collection is passed to each relationships collection so each
219 relationship can resolve a reference to its target part when required. This reference can
220 only be reliably carried out once the all parts have been loaded.
221 """
--> 222 content_types = self._content_types
223 package = self._package
224 package_reader = self._package_reader
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\util.py:191, in lazyproperty.__get__(self, obj, type)
186 value = obj.__dict__.get(self._name)
187 if value is None:
188 # --- on first access, the __dict__ item will be absent. Evaluate fget()
189 # --- and store that value in the (otherwise unused) host-object
190 # --- __dict__ value of same name ('fget' nominally)
--> 191 value = self._fget(obj)
192 obj.__dict__[self._name] = value
193 return cast(_T, value)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py:207, in _PackageLoader._content_types(self)
201 @lazyproperty
202 def _content_types(self) -> _ContentTypeMap:
203 """|_ContentTypeMap| object providing content-types for items of this package.
204
205 Provides a content-type (MIME-type) for any given partname.
206 """
--> 207 return _ContentTypeMap.from_xml(self._package_reader[CONTENT_TYPES_URI])
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\serialized.py:38, in PackageReader.__getitem__(self, pack_uri)
36 def __getitem__(self, pack_uri: PackURI) -> bytes:
37 """Return bytes for part corresponding to `pack_uri`."""
---> 38 return self._blob_reader[pack_uri]
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\util.py:191, in lazyproperty.__get__(self, obj, type)
186 value = obj.__dict__.get(self._name)
187 if value is None:
188 # --- on first access, the __dict__ item will be absent. Evaluate fget()
189 # --- and store that value in the (otherwise unused) host-object
190 # --- __dict__ value of same name ('fget' nominally)
--> 191 value = self._fget(obj)
192 obj.__dict__[self._name] = value
193 return cast(_T, value)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\serialized.py:52, in PackageReader._blob_reader(self)
49 @lazyproperty
50 def _blob_reader(self) -> _PhysPkgReader:
51 """|_PhysPkgReader| subtype providing read access to the package file."""
---> 52 return _PhysPkgReader.factory(self._pkg_file)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\serialized.py:144, in _PhysPkgReader.factory(cls, pkg_file)
141 if zipfile.is_zipfile(pkg_file):
142 return _ZipPkgReader(pkg_file)
--> 144 raise PackageNotFoundError("Package not found at '%s'" % pkg_file)
PackageNotFoundError: Package not found at '原始文件.pptx'