Cython dynamic library problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tommy Grav

    Cython dynamic library problem

    I am trying to learn how to use cython, and while I am following the
    cython-dev
    mailing list I didn't feel like this question was totally appropriate
    for its audience
    so I am trying here first.

    I am on a max os x 10.5.4 running

    drtgrav% python
    ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
    Python 2.5.2 (r252:60911, Mar 27 2008, 17:40:23)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright" , "credits" or "license" for more information.
    >>>
    I have a pure python file that I am wanting to try to speed up some,
    so I ran the file through cython, compiled it with gcc and tried to
    call it from a python file
    cython integrations.py x
    gcc -arch ppc -shared -c -fPIC -I/usr/include/python2.5
    integration.c -o pyx_integration .so
    python integration_tes t.py
    Traceback (most recent call last):
    File "integration_te st.py", line 1, in <module>
    from astroPyX import pyx_integration
    ImportError: dlopen(/Users/drtgrav/Work/myCode/Python/astroPyX/
    pyx_integration .so, 2): no suitable image found. Did find:
    /Users/drtgrav/Work/myCode/Python/astroPyX/pyx_integration .so: can't
    map

    where integration_tes t.py is

    from astroPyX import pyx_integration

    pyx_integration .test(0)
    pyx_integration .test(100)

    Does anyone know what the ImportError means and how to correct it?

    Cheers
    Tommy
  • Rob Wolfe

    #2
    Re: Cython dynamic library problem

    Tommy Grav <tgrav@mac.comw rites:
    I am trying to learn how to use cython, and while I am following the
    cython-dev
    mailing list I didn't feel like this question was totally appropriate
    for its audience
    so I am trying here first.
    [...]
    Does anyone know what the ImportError means and how to correct it?
    I would try to use `distutils` because this package is much wiser
    than me and knows all necessary switches for gcc. ;)

    # test_cython.pyx
    def test(x):
    return x * x

    # test_cython.py
    from pyx_test import test

    print test(0)
    print test(10)

    # setup.py
    from distutils.core import setup
    from distutils.exten sion import Extension
    from Cython.Distutil s import build_ext as build_pyx

    setup(name = 'pyx_test',
    ext_modules=[Extension('pyx_ test', ['test_cython.py x'])],
    cmdclass = { 'build_ext': build_pyx })


    $ python2.5 setup.py build_ext -i
    running build_ext
    cythoning test_cython.pyx to test_cython.c
    building 'pyx_test' extension
    creating build/temp.linux-i686-2.5
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_cython.c -o build/temp.linux-i686-2.5/test_cython.o
    test_cython.c:8 6: warning: function declaration isnft a prototype
    test_cython.c:2 41: warning: function declaration isnft a prototype
    test_cython.c:5 9: warning: e__pyx_skip_di spatchf defined but not used
    gcc -pthread -shared -Wl,-O1 build/temp.linux-i686-2.5/test_cython.o -o pyx_test.so
    $ python2.5 test_cython.py
    0
    100


    HTH,
    Rob

    Comment

    • bearophileHUGS@lycos.com

      #3
      Re: Cython dynamic library problem

      Rob Wolfe:
      # setup.py
      from distutils.core import setup
      from distutils.exten sion import Extension
      from Cython.Distutil s import build_ext as build_pyx
      >
      setup(name = 'pyx_test',
      ext_modules=[Extension('pyx_ test', ['test_cython.py x'])],
      cmdclass = { 'build_ext': build_pyx })
      >
      $ python2.5 setup.py build_ext -i
      running build_ext
      cythoning test_cython.pyx to test_cython.c
      building 'pyx_test' extension
      creating build/temp.linux-i686-2.5
      gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_cython.c -o build/temp.linux-i686-2.5/test_cython.o
      test_cython.c:8 6: warning: function declaration isn’t a prototype
      test_cython.c:2 41: warning: function declaration isn’t a prototype
      test_cython.c:5 9: warning: ‘__pyx_skip_dis patch’ defined but not used
      gcc -pthread -shared -Wl,-O1 build/temp.linux-i686-2.5/test_cython.o -o pyx_test.so
      $ python2.5 test_cython.py
      0
      100
      With some intelligence added to Cython, probably there are ways to
      reduce all this, and most of the times avoid any setup.py module too.

      Bye,
      bearophile

      Comment

      • Tommy Grav

        #4
        Re: Cython dynamic library problem

        On Sep 18, 2008, at 12:35 PM, Rob Wolfe wrote:
        I would try to use `distutils` because this package is much wiser
        than me and knows all necessary switches for gcc. ;)
        That worked! Thanks

        Cheers
        Tommy

        Comment

        • Tommy Grav

          #5
          Re: Cython dynamic library problem


          On Sep 18, 2008, at 12:35 PM, Rob Wolfe wrote:
          >
          I would try to use `distutils` because this package is much wiser
          than me and knows all necessary switches for gcc. ;)
          That worked! Thanks

          Cheers
          Tommy

          Comment

          Working...