python extension modules within packages not loading

Matthew Woodcraft mattheww at chiark.greenend.org.uk
Thu Sep 7 21:25:23 CEST 2006


tyler <tyler.retzlaff at gmail.com> wrote:
> I've written a small python extension but I'm having difficulty loading
> it at runtime.  The source for my extension is a module which is a
> member of a package is organized as follows.
>
> test/setup.py
> test/myutils/__init__.py
> test/myutils/netmodule.c

[...]

> Noticing it appears to be using a relative path I decided to try again
> and this time I chdir() to /usr/lib/python2.4/site-extensions directory
> before launching the interpreter and it then it works perfectly fine.
> Of course I shouldn't have to set my cwd to the site-extensions
> directory before using my extension module..

It looks to me like the problem is that you have a 'myutils'
subdirectory inside the directory that you're starting the interpreter
in. Are you running it from the 'test' directory?

When you use the interactive interpreter, Python's default search path
for modules and packages includes the current directory as the first
entry, so it's finding 'myutils' there rather than in
/usr/lib/python2.4/site-packages.

If that's right, then to avoid this problem you can either run Python
from any other directory, or put a copy of your 'net.so' in the local
'myutils' too.

-M-




More information about the Python-list mailing list