Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problem with custom extension: help needed

Reply
Thread Tools

Problem with custom extension: help needed

 
 
Jose Vicente Nunez Z
Guest
Posts: n/a
 
      09-11-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@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@linux0037 root]# rpm -ihv
/home/josevnz/python/TestNative/dist/python-TestNative-0.0-1.i386.rpm
Preparing... ###########################################
[100%]
1ython-TestNative ###########################################
[100%]

[root@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@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@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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
Help needed on this 857W config. Repost to be clearer what the problemsare and the help needed sparticle Cisco 3 08-30-2007 07:47 PM
Ideas needed & help needed! Ryan Macy Ruby 2 07-19-2006 08:04 PM
Custom membership provider - help needed =?Utf-8?B?a3ZyOTAx?= ASP .Net 1 05-16-2006 08:53 PM
Microsoft small business server 2003 - help needed to understand what is needed to use it Dima Computer Support 5 10-20-2004 08:27 PM



Advertisments