[Hack] Import binary extensions from zipfiles, windows only

PJDM PeterMayne at ap.spherion.com
Mon Jan 3 22:25:02 EST 2005


I'm trying to make ZopeX3 start faster by zipping up the "zope"
directory. (Because this will be stored on a CD, having less data to
read will make it quicker to start.)

The standard python zipimporter won't work with the ZopeX3 .pyd files,
so zipextimporter came along at just the right time. However, it
doesn't seem to work for me (Python 2.3.4 (#53, May 25 2004, 21:17:02)
[MSC v.1200 32 bit (Intel)] on win32, Windows XP SP2).

Sample script:
----
import zipextimporter
zipextimporter.install()

import sys
print 'Hooks:\n', sys.path_hooks

sys.path.append(r'C:\tmp\zope.zip')
print 'Path:\n', sys.path

# Try an innocuous import first to make sure we have the path correct.
import zope.server
print 'Server file:\n', zope.server.__file__

# Now try a .pyd import.
import zope.thread._zope_thread
print 'Thread file:\n', zope.thread._zope_thread.__file__
----

Output:
----
Hooks:
[<class 'zipextimporter.ZipExtensionImporter'>, <type
'zipimport.zipimporter'>]
Path:
['C:\\tmp', 'C:\\WINDOWS\\system32\\python23.zip', 'C:\\tmp',
'C:\\opt\\Python23\\DLLs', 'C:\\opt\\Python23\\lib',
'C:\\opt\\Python23\\lib\\plat-win', 'C:\\opt\\Python23\\lib\\lib-tk',
'C:\\opt\\Python23', 'C:\\opt\\Python23\\lib\\site-packages',
'C:\\tmp\\zope.zip']
Server file:
C:\tmp\zope.zip\zope\server\__init__.py
Traceback (most recent call last):
File "zei.py", line 15, in ?
import zope.thread._zope_thread
ImportError: No module named _zope_thread
----

The zope.zip file contains zope.thread:
----
$ unzip -l zope.zip |grep zope/thread
0  11-08-04 11:00   zope/thread/
0  07-03-04 04:34   zope/thread/DEPENDENCIES.cfg
65  07-28-04 22:52   zope/thread/SETUP.cfg
994  07-03-04 04:34   zope/thread/tests.py
748  11-08-04 11:00   zope/thread/tests.pyc
748  11-08-04 11:00   zope/thread/tests.pyo
20480  11-07-04 00:54   zope/thread/_zope_thread.pyd
7838  08-17-04 17:20   zope/thread/__init__.py
7808  11-08-04 11:00   zope/thread/__init__.pyc
7808  11-08-04 11:00   zope/thread/__init__.pyo
----

What am I missing?

Thanks.

PJDM




More information about the Python-list mailing list