<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-pkgutil.html" />
<link rel=
"prev" href=
"module-imp.html" />
<link rel=
"parent" href=
"python.html" />
<link rel=
"next" href=
"zipimporter-objects.html" />
<meta name='aesop' content='information'
/>
<title>3.22 zipimport -- Import modules from Zip archives
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"3.21.1 Examples"
href=
"examples-imp.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"3. Python Runtime Services"
href=
"python.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"3.22.1 zipimporter Objects"
href=
"zipimporter-objects.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"examples-imp.html">3.21.1 Examples
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"python.html">3. Python Runtime Services
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"zipimporter-objects.html">3.22.1 zipimporter Objects
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION0052200000000000000000">
3.22 <tt class=
"module">zipimport
</tt> --
Import modules from Zip archives
</A>
<A NAME=
"module-zipimport"></A>
<span class=
"versionnote">New in version
2.3.
</span>
This module adds the ability to import Python modules (
<span class=
"file">*.py
</span>,
<span class=
"file">*.py[co]
</span>) and packages from ZIP-format archives. It is usually
not needed to use the
<tt class=
"module">zipimport
</tt> module explicitly; it is
automatically used by the builtin
<tt class=
"keyword">import
</tt> mechanism for
<code>sys.path
</code> items that are paths to ZIP archives.
Typically,
<code>sys.path
</code> is a list of directory names as strings. This
module also allows an item of
<code>sys.path
</code> to be a string naming a ZIP
file archive. The ZIP archive can contain a subdirectory structure to
support package imports, and a path within the archive can be specified to
only import from a subdirectory. For example, the path
<span class=
"file">/tmp/example.zip/lib/
</span> would only import from the
<span class=
"file">lib/
</span> subdirectory within the archive.
Any files may be present in the ZIP archive, but only files
<span class=
"file">.py
</span> and
<span class=
"file">.py[co]
</span> are available for import. ZIP import of dynamic modules
(
<span class=
"file">.pyd
</span>,
<span class=
"file">.so
</span>) is disallowed. Note that if an archive only
contains
<span class=
"file">.py
</span> files, Python will not attempt to modify the archive
by adding the corresponding
<span class=
"file">.pyc
</span> or
<span class=
"file">.pyo
</span> file, meaning that
if a ZIP archive doesn't contain
<span class=
"file">.pyc
</span> files, importing may be rather
Using the built-in
<tt class=
"function">reload()
</tt> function will
fail if called on a module loaded from a ZIP archive; it is unlikely that
<tt class=
"function">reload()
</tt> would be needed, since this would imply that the ZIP
has been altered during runtime.
The available attributes of this module are:
<dl><dt><b><span class=
"typelabel">exception
</span> <tt id='l2h-
726' xml:id='l2h-
726'
class=
"exception">ZipImporterError
</tt></b></dt>
Exception raised by zipimporter objects. It's a subclass of
<tt class=
"exception">ImportError
</tt>, so it can be caught as
<tt class=
"exception">ImportError
</tt>,
<dl><dt><b><span class=
"typelabel">class
</span> <tt id='l2h-
727' xml:id='l2h-
727'
class=
"class">zipimporter
</tt></b>
The class for importing ZIP files. See
>zipimporter Objects
</em>'' (section
<A href=
"zipimporter-objects.html#zipimporter-objects">3.22.1</A>)
<p class=
"heading">See Also:
</p>
<dl compact=
"compact" class=
"seetitle">
<dt><em class=
"citetitle"><a href=
"http://www.pkware.com/appnote.html"
<dd>Documentation on the ZIP file format by Phil
Katz, the creator of the format and algorithms used.
</dd>
<dl compact=
"compact" class=
"seerfc">
<dt><a href=
"http://www.python.org/peps/pep-0273.html"
title=
"Import Modules from Zip Archives"
>PEP
0273,
<em>Import Modules from Zip Archives
</em></a>
Ahlstrom, who also provided an implementation. Python
2.3
follows the specification in PEP
273, but uses an
implementation written by Just van Rossum that uses the import
hooks described in PEP
302.
<dl compact=
"compact" class=
"seerfc">
<dt><a href=
"http://www.python.org/peps/pep-0302.html"
>PEP
0302,
<em>New Import Hooks
</em></a>
<dd>The PEP to add the import hooks that help
<p><br /></p><hr class='online-navigation'
/>
<div class='online-navigation'
>
<!--Table of Child-Links-->
<A NAME=
"CHILD_LINKS"><STRONG>Subsections
</STRONG></a>
<LI><A href=
"zipimporter-objects.html">3.22.1 zipimporter Objects
</a>
<LI><A href=
"node88.html">3.22.2 Examples
</a>
<!--End of Table of Child-Links-->
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"3.21.1 Examples"
href=
"examples-imp.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"3. Python Runtime Services"
href=
"python.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"3.22.1 zipimporter Objects"
href=
"zipimporter-objects.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"examples-imp.html">3.21.1 Examples
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"python.html">3. Python Runtime Services
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"zipimporter-objects.html">3.22.1 zipimporter Objects
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.