Problem with custom extension: help needed

Jose Vicente Nunez Z josevnz at newbreak.com
Thu Sep 11 11:02:16 EDT 2003


Greetings,


I wrote a couple of custom dummy extensions in Python (one a pure Python
and the other a C) and i managed to compile and install them without a
problem:

[josevnz at linux0037 TestNative]$ make
python2 setup.py build
running build
running build_py
creating build
creating build/lib.linux-i686-2.2
creating build/lib.linux-i686-2.2/test
copying src/python/test/Dummy.py -> build/lib.linux-i686-2.2/test
copying src/python/test/__init__.py -> build/lib.linux-i686-2.2/test
running build_ext
building 'test.NativeDummy' extension
creating build/temp.linux-i686-2.2
gcc -DNDEBUG -O2 -g -pipe -march=i386 -mcpu=i686 -D_GNU_SOURCE -fPIC
-fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=0 -I/include
-I/usr/include/python2.2 -c src/c/dummy.c -o
build/temp.linux-i686-2.2/dummy.o
gcc -shared build/temp.linux-i686-2.2/dummy.o -L/lib -lm -o
build/lib.linux-i686-2.2/test/NativeDummy.so

So far the RPM installation looks ok too and seems to be than the
installed files are on the proper location:

make rpm
....
moving build/bdist.linux-i686/rpm/SRPMS/python-TestNative-0.0-1.src.rpm
-> dist
moving
build/bdist.linux-i686/rpm/RPMS/i386/python-TestNative-0.0-1.i386.rpm ->
dist

[root at linux0037 root]# rpm -ihv
/home/josevnz/python/TestNative/dist/python-TestNative-0.0-1.i386.rpm
Preparing...                ###########################################
[100%]
   1:python-TestNative      ###########################################
[100%]

[root at linux0037 root]# rpm -ql python-TestNative
/usr/lib/python2.2/site-packages/test/Dummy.py
/usr/lib/python2.2/site-packages/test/Dummy.pyc
/usr/lib/python2.2/site-packages/test/NativeDummy.so
/usr/lib/python2.2/site-packages/test/__init__.py
/usr/lib/python2.2/site-packages/test/__init__.pyc


But when i run a custom script that uses both extensions i got the
following error:

[josevnz at linux0037 TestNative]$ ./scripts/Test.py
./scripts
/usr/lib/python2.2
/usr/lib/python2.2/plat-linux2
/usr/lib/python2.2/lib-tk
/usr/lib/python2.2/lib-dynload
/usr/lib/python2.2/site-packages
/usr/lib/python2.2/site-packages/gtk-2.0
/usr/lib/python2.2/site-packages/test
Traceback (most recent call last):
  File "./scripts/Test.py", line 18, in ?
    import test.Dummy
ImportError: No module named Dummy
[josevnz at linux0037 TestNative]$


The script code seems normal to me:

#!/usr/bin/env python2
#
# Hello world to test native interfaces in Python
#
# Fix the path
import os.path
import sys
new_path="/usr/lib/python2.2/site-packages/test"
new_path=os.path.abspath(new_path)
sys.path.append(new_path)
debug=1

if debug:
for path in sys.path:
print path

import test.Dummy
import test.NativeDummy

argument1 = "Test string argument"
argument2 = 600000
dumber = test.Dummy.Dummy("really dumb")
test.NativeDummy(argument1, argument2)


Here is my setup.py file:

#!/usr/bin/env python2
#
# Hello world to test native interfaces in Python
#
from distutils.core import setup, Extension

VERSION=0
RELEASE=0

extension1 = Extension('test.NativeDummy',
                    define_macros = [('MAJOR_VERSION', VERSION),
                                     ('MINOR_VERSION', RELEASE)],
                    include_dirs = ['/include'],
                    libraries = ['m'],
                    library_dirs = ['/lib'],
                    sources = ['src/c/dummy.c'])

setup (name = 'python-TestNative',
       version = '0.0',
       description = 'My practice native test with Python.',
       author = 'Jose Vicente Nunez Zuleta',
       author_email = 'ZZZZZ',
       url = 'XXXX',
       package_dir = {'' : 'src/python'},
       packages = ['test'],
       long_description = '''
My practice native test with Python.
Hope this works.
''',
       ext_modules = [extension1])

I'm using Python 2.2 on RedHat7.2

What do i need to fix so Python can load my extensions?

Thanks in advance,


-- 
Jose Vicente Nunez Zuleta (josevnz at newbreak dot com)
Newbreak LLC System Administrator
http://www.newbreak.com






More information about the Python-list mailing list