<p>I am creating an ZIP file with <code>ZipFile</code> in Python 2.5, it works OK so far:</p>
<pre><code>import zipfile, os

locfile = &quot;test.txt&quot;
loczip = os.path.splitext (locfile)[0] + &quot;.zip&quot;
zip = zipfile.ZipFile (loczip, &quot;w&quot;)
zip.write (locfile)
zip.close()
</code></pre>
<p>But I couldn't find how to encrypt the files in the ZIP file.
I could use system and call <code>PKZIP -s</code>, but I suppose there must be a more &quot;Pythonic&quot; way.  I'm looking for an open source solution.</p>

You can use the
Chilkat
library.  It's commercial, but has a free evaluation and seems pretty nice.
Here's an example I got from
here
:
```
```
import chilkat

# Demonstrates how to create a WinZip-compatible 128-bit AES strong encrypted zip
zip = chilkat.CkZip()
zip.UnlockComponent("anything for 30-day trial")

zip.NewZip("strongEncrypted.zip")

# Set the Encryption property = 4, which indicates WinZip compatible AES encryption.
zip.put_Encryption(4)
# The key length can be 128, 192, or 256.
zip.put_EncryptKeyLength(128)
zip.SetPassword("secret")

zip.AppendFiles("exampleData/*",True)
zip.WriteZip()
```
```