473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

python extension modules within packages not loading

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

my setup.py file for building / installing looks like this

setup(ext_package = 'myutils',
ext_modules = [ Extension('net', sources = [ 'myutils/netmodule.c'
]) ],
packages = [ 'myutils'])

as per the faq I've been building and installing it with

python setup.py build
python setup.py install

which results in the following being installed into my site-packages
directory.

/usr/lib/python2.4/site-packages/myutils/__init__.py
/usr/lib/python2.4/site-packages/myutils/__init__.pyc
/usr/lib/python2.4/site-packages/myutils/net.so

when I run the interpreter and try to import the modules however I get
no joy.
>>>import myutils
import myutils.net
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named net

now annoyed I strace the interpreter during the loading of the module
and see.

stat64("myutils", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("myutils/__init__.py", {st_mode=S_IFREG|0644, st_size=0, ...}) =
0
stat64("myutils/__init__", 0xbf8d3a6c) = -1 ENOENT (No such file or
directory)
open("myutils/__init__.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such
file or directory)
open("myutils/__init__module.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No
such file or directory)
open("myutils/__init__.py", O_RDONLY|O_LARGEFILE) = 3

clearly the above corresponds to my first import statement and it
appears to have been successful. A little further along in the trace
however I see the following.

stat64("myutils", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("myutils/net", 0xbf8d3ebc) = -1 ENOENT (No such file or
directory)
open("myutils/net.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file
or directory)
open("myutils/netmodule.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such
file or directory)
open("myutils/net.py", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file
or directory)
open("myutils/net.pyc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file
or directory)

clearly the above corresponds to my second import statement but for
some reason it fails with ENOENT when trying to open myutils/net.so
which definately exists.

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..

How do I fix this? What have I done wrong?

Help very much appreciated, thanks.

Tyler

Sep 7 '06 #1
1 2084
tyler <ty************@gmail.comwrote:
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-

Sep 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
4
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or...
3
by: Matthias Baas | last post by:
Hi, are there any guidelines about what to do if a Windows extension for Python 2.4 requires the C++ runtime (msvcp71.dll)? If I want to distribute a binary installer of an extension that...
1
by: Mark Asbach | last post by:
Hi pythonians, I'm one of the maintainers of an open source image processing toolkit (OpenCV) and responsible for parts of the autotools setup. The package mainly consists of four shared...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
15
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.