Problem with custom extension: help needed

Discussion in 'Python' started by Jose Vicente Nunez Z, Sep 11, 2003.

  1. 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%]
    1:python-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
     
    Jose Vicente Nunez Z, Sep 11, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand
    Replies:
    3
    Views:
    899
    Tim Daneliuk
    Nov 8, 2003
  2. Michael
    Replies:
    3
    Views:
    206
    Jerry Goldin
    May 12, 2004
  3. Scott Raymond
    Replies:
    4
    Views:
    125
    Devin Mullins
    Dec 23, 2005
  4. Iñaki Baz Castillo
    Replies:
    2
    Views:
    228
    Iñaki Baz Castillo
    Apr 20, 2011
  5. Simon Hardy-Francis
    Replies:
    2
    Views:
    62
    Rustom Mody
    Mar 23, 2014
Loading...

Share This Page