gooderp18绿色标准版
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

528 行
34KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="zipimport — Import modules from Zip archives" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/zipimport.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/zipimport.py This module adds the ability to import Python modules (*.py,*.pyc) and packages from ZIP-format archives. It is usually not needed to use the zipimport module explicit..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/zipimport.py This module adds the ability to import Python modules (*.py,*.pyc) and packages from ZIP-format archives. It is usually not needed to use the zipimport module explicit..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>zipimport — Import modules from Zip archives &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="pkgutil — Package extension utility" href="pkgutil.html" />
  33. <link rel="prev" title="Importing Modules" href="modules.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/zipimport.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code> — Import modules from Zip archives</a><ul>
  86. <li><a class="reference internal" href="#zipimporter-objects">zipimporter Objects</a></li>
  87. <li><a class="reference internal" href="#examples">Examples</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div>
  92. <div>
  93. <h4>Previous topic</h4>
  94. <p class="topless"><a href="modules.html"
  95. title="previous chapter">Importing Modules</a></p>
  96. </div>
  97. <div>
  98. <h4>Next topic</h4>
  99. <p class="topless"><a href="pkgutil.html"
  100. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code> — Package extension utility</a></p>
  101. </div>
  102. <div role="note" aria-label="source link">
  103. <h3>This Page</h3>
  104. <ul class="this-page-menu">
  105. <li><a href="../bugs.html">Report a Bug</a></li>
  106. <li>
  107. <a href="https://github.com/python/cpython/blob/main/Doc/library/zipimport.rst"
  108. rel="nofollow">Show Source
  109. </a>
  110. </li>
  111. </ul>
  112. </div>
  113. </nav>
  114. </div>
  115. </div>
  116. <div class="related" role="navigation" aria-label="related navigation">
  117. <h3>Navigation</h3>
  118. <ul>
  119. <li class="right" style="margin-right: 10px">
  120. <a href="../genindex.html" title="General Index"
  121. accesskey="I">index</a></li>
  122. <li class="right" >
  123. <a href="../py-modindex.html" title="Python Module Index"
  124. >modules</a> |</li>
  125. <li class="right" >
  126. <a href="pkgutil.html" title="pkgutil — Package extension utility"
  127. accesskey="N">next</a> |</li>
  128. <li class="right" >
  129. <a href="modules.html" title="Importing Modules"
  130. accesskey="P">previous</a> |</li>
  131. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  132. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  133. <li class="switchers">
  134. <div class="language_switcher_placeholder"></div>
  135. <div class="version_switcher_placeholder"></div>
  136. </li>
  137. <li>
  138. </li>
  139. <li id="cpython-language-and-version">
  140. <a href="../index.html">3.12.3 Documentation</a> &#187;
  141. </li>
  142. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  143. <li class="nav-item nav-item-2"><a href="modules.html" accesskey="U">Importing Modules</a> &#187;</li>
  144. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code> — Import modules from Zip archives</a></li>
  145. <li class="right">
  146. <div class="inline-search" role="search">
  147. <form class="inline-search" action="../search.html" method="get">
  148. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  149. <input type="submit" value="Go" />
  150. </form>
  151. </div>
  152. |
  153. </li>
  154. <li class="right">
  155. <label class="theme-selector-label">
  156. Theme
  157. <select class="theme-selector" oninput="activateTheme(this.value)">
  158. <option value="auto" selected>Auto</option>
  159. <option value="light">Light</option>
  160. <option value="dark">Dark</option>
  161. </select>
  162. </label> |</li>
  163. </ul>
  164. </div>
  165. <div class="document">
  166. <div class="documentwrapper">
  167. <div class="bodywrapper">
  168. <div class="body" role="main">
  169. <section id="module-zipimport">
  170. <span id="zipimport-import-modules-from-zip-archives"></span><h1><a class="reference internal" href="#module-zipimport" title="zipimport: Support for importing Python modules from ZIP archives."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code></a> — Import modules from Zip archives<a class="headerlink" href="#module-zipimport" title="Link to this heading">¶</a></h1>
  171. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/zipimport.py">Lib/zipimport.py</a></p>
  172. <hr class="docutils" />
  173. <p>This module adds the ability to import Python modules (<code class="file docutils literal notranslate"><span class="pre">*.py</span></code>,
  174. <code class="file docutils literal notranslate"><span class="pre">*.pyc</span></code>) and packages from ZIP-format archives. It is usually not
  175. needed to use the <a class="reference internal" href="#module-zipimport" title="zipimport: Support for importing Python modules from ZIP archives."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code></a> module explicitly; it is automatically used
  176. by the built-in <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> mechanism for <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> items that are paths
  177. to ZIP archives.</p>
  178. <p>Typically, <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> is a list of directory names as strings. This module
  179. also allows an item of <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> to be a string naming a ZIP file archive.
  180. The ZIP archive can contain a subdirectory structure to support package imports,
  181. and a path within the archive can be specified to only import from a
  182. subdirectory. For example, the path <code class="file docutils literal notranslate"><span class="pre">example.zip/lib/</span></code> would only
  183. import from the <code class="file docutils literal notranslate"><span class="pre">lib/</span></code> subdirectory within the archive.</p>
  184. <p>Any files may be present in the ZIP archive, but importers are only invoked for
  185. <code class="file docutils literal notranslate"><span class="pre">.py</span></code> and <code class="file docutils literal notranslate"><span class="pre">.pyc</span></code> files. ZIP import of dynamic modules
  186. (<code class="file docutils literal notranslate"><span class="pre">.pyd</span></code>, <code class="file docutils literal notranslate"><span class="pre">.so</span></code>) is disallowed. Note that if an archive only contains
  187. <code class="file docutils literal notranslate"><span class="pre">.py</span></code> files, Python will not attempt to modify the archive by adding the
  188. corresponding <code class="file docutils literal notranslate"><span class="pre">.pyc</span></code> file, meaning that if a ZIP archive
  189. doesn’t contain <code class="file docutils literal notranslate"><span class="pre">.pyc</span></code> files, importing may be rather slow.</p>
  190. <div class="versionchanged">
  191. <p><span class="versionmodified changed">Changed in version 3.8: </span>Previously, ZIP archives with an archive comment were not supported.</p>
  192. </div>
  193. <div class="admonition seealso">
  194. <p class="admonition-title">See also</p>
  195. <dl class="simple">
  196. <dt><a class="reference external" href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT">PKZIP Application Note</a></dt><dd><p>Documentation on the ZIP file format by Phil Katz, the creator of the format and
  197. algorithms used.</p>
  198. </dd>
  199. <dt><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0273/"><strong>PEP 273</strong></a> - Import Modules from Zip Archives</dt><dd><p>Written by James C. Ahlstrom, who also provided an implementation. Python 2.3
  200. follows the specification in <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0273/"><strong>PEP 273</strong></a>, but uses an implementation written by Just
  201. van Rossum that uses the import hooks described in <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0302/"><strong>PEP 302</strong></a>.</p>
  202. </dd>
  203. <dt><a class="reference internal" href="importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> - The implementation of the import machinery</dt><dd><p>Package providing the relevant protocols for all importers to
  204. implement.</p>
  205. </dd>
  206. </dl>
  207. </div>
  208. <p>This module defines an exception:</p>
  209. <dl class="py exception">
  210. <dt class="sig sig-object py" id="zipimport.ZipImportError">
  211. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">zipimport.</span></span><span class="sig-name descname"><span class="pre">ZipImportError</span></span><a class="headerlink" href="#zipimport.ZipImportError" title="Link to this definition">¶</a></dt>
  212. <dd><p>Exception raised by zipimporter objects. It’s a subclass of <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>,
  213. so it can be caught as <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>, too.</p>
  214. </dd></dl>
  215. <section id="zipimporter-objects">
  216. <span id="id1"></span><h2>zipimporter Objects<a class="headerlink" href="#zipimporter-objects" title="Link to this heading">¶</a></h2>
  217. <p><a class="reference internal" href="#zipimport.zipimporter" title="zipimport.zipimporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">zipimporter</span></code></a> is the class for importing ZIP files.</p>
  218. <dl class="py class">
  219. <dt class="sig sig-object py" id="zipimport.zipimporter">
  220. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">zipimport.</span></span><span class="sig-name descname"><span class="pre">zipimporter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">archivepath</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter" title="Link to this definition">¶</a></dt>
  221. <dd><p>Create a new zipimporter instance. <em>archivepath</em> must be a path to a ZIP
  222. file, or to a specific path within a ZIP file. For example, an <em>archivepath</em>
  223. of <code class="file docutils literal notranslate"><span class="pre">foo/bar.zip/lib</span></code> will look for modules in the <code class="file docutils literal notranslate"><span class="pre">lib</span></code> directory
  224. inside the ZIP file <code class="file docutils literal notranslate"><span class="pre">foo/bar.zip</span></code> (provided that it exists).</p>
  225. <p><a class="reference internal" href="#zipimport.ZipImportError" title="zipimport.ZipImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZipImportError</span></code></a> is raised if <em>archivepath</em> doesn’t point to a valid ZIP
  226. archive.</p>
  227. <div class="versionchanged">
  228. <p><span class="versionmodified changed">Changed in version 3.12: </span>Methods <code class="docutils literal notranslate"><span class="pre">find_loader()</span></code> and <code class="docutils literal notranslate"><span class="pre">find_module()</span></code>, deprecated in 3.10 are
  229. now removed. Use <a class="reference internal" href="#zipimport.zipimporter.find_spec" title="zipimport.zipimporter.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> instead.</p>
  230. </div>
  231. <dl class="py method">
  232. <dt class="sig sig-object py" id="zipimport.zipimporter.create_module">
  233. <span class="sig-name descname"><span class="pre">create_module</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">spec</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.create_module" title="Link to this definition">¶</a></dt>
  234. <dd><p>Implementation of <a class="reference internal" href="importlib.html#importlib.abc.Loader.create_module" title="importlib.abc.Loader.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.create_module()</span></code></a> that returns
  235. <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> to explicitly request the default semantics.</p>
  236. <div class="versionadded">
  237. <p><span class="versionmodified added">New in version 3.10.</span></p>
  238. </div>
  239. </dd></dl>
  240. <dl class="py method">
  241. <dt class="sig sig-object py" id="zipimport.zipimporter.exec_module">
  242. <span class="sig-name descname"><span class="pre">exec_module</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">module</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.exec_module" title="Link to this definition">¶</a></dt>
  243. <dd><p>Implementation of <a class="reference internal" href="importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a>.</p>
  244. <div class="versionadded">
  245. <p><span class="versionmodified added">New in version 3.10.</span></p>
  246. </div>
  247. </dd></dl>
  248. <dl class="py method">
  249. <dt class="sig sig-object py" id="zipimport.zipimporter.find_spec">
  250. <span class="sig-name descname"><span class="pre">find_spec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.find_spec" title="Link to this definition">¶</a></dt>
  251. <dd><p>An implementation of <a class="reference internal" href="importlib.html#importlib.abc.PathEntryFinder.find_spec" title="importlib.abc.PathEntryFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_spec()</span></code></a>.</p>
  252. <div class="versionadded">
  253. <p><span class="versionmodified added">New in version 3.10.</span></p>
  254. </div>
  255. </dd></dl>
  256. <dl class="py method">
  257. <dt class="sig sig-object py" id="zipimport.zipimporter.get_code">
  258. <span class="sig-name descname"><span class="pre">get_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.get_code" title="Link to this definition">¶</a></dt>
  259. <dd><p>Return the code object for the specified module. Raise
  260. <a class="reference internal" href="#zipimport.ZipImportError" title="zipimport.ZipImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZipImportError</span></code></a> if the module couldn’t be imported.</p>
  261. </dd></dl>
  262. <dl class="py method">
  263. <dt class="sig sig-object py" id="zipimport.zipimporter.get_data">
  264. <span class="sig-name descname"><span class="pre">get_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pathname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.get_data" title="Link to this definition">¶</a></dt>
  265. <dd><p>Return the data associated with <em>pathname</em>. Raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if the
  266. file wasn’t found.</p>
  267. <div class="versionchanged">
  268. <p><span class="versionmodified changed">Changed in version 3.3: </span><a class="reference internal" href="exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a> used to be raised, it is now an alias of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
  269. </div>
  270. </dd></dl>
  271. <dl class="py method">
  272. <dt class="sig sig-object py" id="zipimport.zipimporter.get_filename">
  273. <span class="sig-name descname"><span class="pre">get_filename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.get_filename" title="Link to this definition">¶</a></dt>
  274. <dd><p>Return the value <code class="docutils literal notranslate"><span class="pre">__file__</span></code> would be set to if the specified module
  275. was imported. Raise <a class="reference internal" href="#zipimport.ZipImportError" title="zipimport.ZipImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZipImportError</span></code></a> if the module couldn’t be
  276. imported.</p>
  277. <div class="versionadded">
  278. <p><span class="versionmodified added">New in version 3.1.</span></p>
  279. </div>
  280. </dd></dl>
  281. <dl class="py method">
  282. <dt class="sig sig-object py" id="zipimport.zipimporter.get_source">
  283. <span class="sig-name descname"><span class="pre">get_source</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.get_source" title="Link to this definition">¶</a></dt>
  284. <dd><p>Return the source code for the specified module. Raise
  285. <a class="reference internal" href="#zipimport.ZipImportError" title="zipimport.ZipImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZipImportError</span></code></a> if the module couldn’t be found, return
  286. <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> if the archive does contain the module, but has no source
  287. for it.</p>
  288. </dd></dl>
  289. <dl class="py method">
  290. <dt class="sig sig-object py" id="zipimport.zipimporter.is_package">
  291. <span class="sig-name descname"><span class="pre">is_package</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.is_package" title="Link to this definition">¶</a></dt>
  292. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the module specified by <em>fullname</em> is a package. Raise
  293. <a class="reference internal" href="#zipimport.ZipImportError" title="zipimport.ZipImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZipImportError</span></code></a> if the module couldn’t be found.</p>
  294. </dd></dl>
  295. <dl class="py method">
  296. <dt class="sig sig-object py" id="zipimport.zipimporter.load_module">
  297. <span class="sig-name descname"><span class="pre">load_module</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.load_module" title="Link to this definition">¶</a></dt>
  298. <dd><p>Load the module specified by <em>fullname</em>. <em>fullname</em> must be the fully
  299. qualified (dotted) module name. Returns the imported module on success,
  300. raises <a class="reference internal" href="#zipimport.ZipImportError" title="zipimport.ZipImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZipImportError</span></code></a> on failure.</p>
  301. <div class="deprecated">
  302. <p><span class="versionmodified deprecated">Deprecated since version 3.10: </span>Use <a class="reference internal" href="#zipimport.zipimporter.exec_module" title="zipimport.zipimporter.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exec_module()</span></code></a> instead.</p>
  303. </div>
  304. </dd></dl>
  305. <dl class="py method">
  306. <dt class="sig sig-object py" id="zipimport.zipimporter.invalidate_caches">
  307. <span class="sig-name descname"><span class="pre">invalidate_caches</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#zipimport.zipimporter.invalidate_caches" title="Link to this definition">¶</a></dt>
  308. <dd><p>Clear out the internal cache of information about files found within
  309. the ZIP archive.</p>
  310. <div class="versionadded">
  311. <p><span class="versionmodified added">New in version 3.10.</span></p>
  312. </div>
  313. </dd></dl>
  314. <dl class="py attribute">
  315. <dt class="sig sig-object py" id="zipimport.zipimporter.archive">
  316. <span class="sig-name descname"><span class="pre">archive</span></span><a class="headerlink" href="#zipimport.zipimporter.archive" title="Link to this definition">¶</a></dt>
  317. <dd><p>The file name of the importer’s associated ZIP file, without a possible
  318. subpath.</p>
  319. </dd></dl>
  320. <dl class="py attribute">
  321. <dt class="sig sig-object py" id="zipimport.zipimporter.prefix">
  322. <span class="sig-name descname"><span class="pre">prefix</span></span><a class="headerlink" href="#zipimport.zipimporter.prefix" title="Link to this definition">¶</a></dt>
  323. <dd><p>The subpath within the ZIP file where modules are searched. This is the
  324. empty string for zipimporter objects which point to the root of the ZIP
  325. file.</p>
  326. </dd></dl>
  327. <p>The <a class="reference internal" href="#zipimport.zipimporter.archive" title="zipimport.zipimporter.archive"><code class="xref py py-attr docutils literal notranslate"><span class="pre">archive</span></code></a> and <a class="reference internal" href="#zipimport.zipimporter.prefix" title="zipimport.zipimporter.prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">prefix</span></code></a> attributes, when combined with a
  328. slash, equal the original <em>archivepath</em> argument given to the
  329. <a class="reference internal" href="#zipimport.zipimporter" title="zipimport.zipimporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">zipimporter</span></code></a> constructor.</p>
  330. </dd></dl>
  331. </section>
  332. <section id="examples">
  333. <span id="zipimport-examples"></span><h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
  334. <p>Here is an example that imports a module from a ZIP archive - note that the
  335. <a class="reference internal" href="#module-zipimport" title="zipimport: Support for importing Python modules from ZIP archives."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code></a> module is not explicitly used.</p>
  336. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>unzip<span class="w"> </span>-l<span class="w"> </span>example.zip
  337. <span class="go">Archive: example.zip</span>
  338. <span class="go"> Length Date Time Name</span>
  339. <span class="go"> -------- ---- ---- ----</span>
  340. <span class="go"> 8467 11-26-02 22:30 jwzthreading.py</span>
  341. <span class="go"> -------- -------</span>
  342. <span class="go"> 8467 1 file</span>
  343. <span class="gp">$ </span>./python
  344. <span class="go">Python 2.3 (#1, Aug 1 2003, 19:54:32)</span>
  345. <span class="go">&gt;&gt;&gt; import sys</span>
  346. <span class="go">&gt;&gt;&gt; sys.path.insert(0, &#39;example.zip&#39;) # Add .zip file to front of path</span>
  347. <span class="go">&gt;&gt;&gt; import jwzthreading</span>
  348. <span class="go">&gt;&gt;&gt; jwzthreading.__file__</span>
  349. <span class="go">&#39;example.zip/jwzthreading.py&#39;</span>
  350. </pre></div>
  351. </div>
  352. </section>
  353. </section>
  354. <div class="clearer"></div>
  355. </div>
  356. </div>
  357. </div>
  358. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  359. <div class="sphinxsidebarwrapper">
  360. <div>
  361. <h3><a href="../contents.html">Table of Contents</a></h3>
  362. <ul>
  363. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code> — Import modules from Zip archives</a><ul>
  364. <li><a class="reference internal" href="#zipimporter-objects">zipimporter Objects</a></li>
  365. <li><a class="reference internal" href="#examples">Examples</a></li>
  366. </ul>
  367. </li>
  368. </ul>
  369. </div>
  370. <div>
  371. <h4>Previous topic</h4>
  372. <p class="topless"><a href="modules.html"
  373. title="previous chapter">Importing Modules</a></p>
  374. </div>
  375. <div>
  376. <h4>Next topic</h4>
  377. <p class="topless"><a href="pkgutil.html"
  378. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code> — Package extension utility</a></p>
  379. </div>
  380. <div role="note" aria-label="source link">
  381. <h3>This Page</h3>
  382. <ul class="this-page-menu">
  383. <li><a href="../bugs.html">Report a Bug</a></li>
  384. <li>
  385. <a href="https://github.com/python/cpython/blob/main/Doc/library/zipimport.rst"
  386. rel="nofollow">Show Source
  387. </a>
  388. </li>
  389. </ul>
  390. </div>
  391. </div>
  392. <div id="sidebarbutton" title="Collapse sidebar">
  393. <span>«</span>
  394. </div>
  395. </div>
  396. <div class="clearer"></div>
  397. </div>
  398. <div class="related" role="navigation" aria-label="related navigation">
  399. <h3>Navigation</h3>
  400. <ul>
  401. <li class="right" style="margin-right: 10px">
  402. <a href="../genindex.html" title="General Index"
  403. >index</a></li>
  404. <li class="right" >
  405. <a href="../py-modindex.html" title="Python Module Index"
  406. >modules</a> |</li>
  407. <li class="right" >
  408. <a href="pkgutil.html" title="pkgutil — Package extension utility"
  409. >next</a> |</li>
  410. <li class="right" >
  411. <a href="modules.html" title="Importing Modules"
  412. >previous</a> |</li>
  413. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  414. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  415. <li class="switchers">
  416. <div class="language_switcher_placeholder"></div>
  417. <div class="version_switcher_placeholder"></div>
  418. </li>
  419. <li>
  420. </li>
  421. <li id="cpython-language-and-version">
  422. <a href="../index.html">3.12.3 Documentation</a> &#187;
  423. </li>
  424. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  425. <li class="nav-item nav-item-2"><a href="modules.html" >Importing Modules</a> &#187;</li>
  426. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code> — Import modules from Zip archives</a></li>
  427. <li class="right">
  428. <div class="inline-search" role="search">
  429. <form class="inline-search" action="../search.html" method="get">
  430. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  431. <input type="submit" value="Go" />
  432. </form>
  433. </div>
  434. |
  435. </li>
  436. <li class="right">
  437. <label class="theme-selector-label">
  438. Theme
  439. <select class="theme-selector" oninput="activateTheme(this.value)">
  440. <option value="auto" selected>Auto</option>
  441. <option value="light">Light</option>
  442. <option value="dark">Dark</option>
  443. </select>
  444. </label> |</li>
  445. </ul>
  446. </div>
  447. <div class="footer">
  448. &copy;
  449. <a href="../copyright.html">
  450. Copyright
  451. </a>
  452. 2001-2024, Python Software Foundation.
  453. <br />
  454. This page is licensed under the Python Software Foundation License Version 2.
  455. <br />
  456. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  457. <br />
  458. See <a href="/license.html">History and License</a> for more information.<br />
  459. <br />
  460. The Python Software Foundation is a non-profit corporation.
  461. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  462. <br />
  463. <br />
  464. Last updated on Apr 09, 2024 (13:47 UTC).
  465. <a href="/bugs.html">Found a bug</a>?
  466. <br />
  467. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  468. </div>
  469. </body>
  470. </html>
上海开阖软件有限公司 沪ICP备12045867号-1