python 3.2b1, importing rpy2 fails

Issue #62 resolved
Former user created an issue

importing rpy2 fails with following error

ImportError: /.../lib/python3.2/site-packages/rpy2/rinterface/rinterface.cpython-32m.so: undefined symbol: PyCObject_FromVoidPtr

Comments (11)

  1. Former user Account Deleted

    the code will fail with python 2.7 i suspect as well (i believe PyCapsule needs to be used)

  2. Laurent Gautier

    If the symbol PyCObject_FromVoidPtr was missing, I suspect that this should have shown up when building rpy2.

    A current snapshot of rpy2-2.2.0-dev is working with Python 2.7 (you do not give an rpy2 version by the way).

    Can you check that the following is not happening with your local installation ? http://stackoverflow.com/questions/1547310/python-3-1-1-with-enable-shared-will-not-build-any-extensions

  3. Former user Account Deleted

    please see

    http://docs.python.org/c-api/cobject.html http://bugs.python.org/issue5630 http://docs.python.org/release/3.1.2/c-api/cobject.html

    please search for "PyCObject_FromVoidPtr PyCapsule python 3" on the net, i.e. via google. ;) according to some of the links PyCObject_* are removed from Python 3.2.

    why it compiles? no idea, but i am getting warnings like

    build/python3_rpy/rpy/rinterface/sexp.c:250:3: warning: implicit declaration of function ‘PyCObject_FromVoidPtr’ build/python3_rpy/rpy/rinterface/sexp.c:250:19: warning: initialization makes pointer from integer without a cast build/python3_rpy/rpy/rinterface/sexp.c: In function ‘Sexp_sexp_set’: build/python3_rpy/rpy/rinterface/sexp.c:258:3: warning: implicit declaration of function ‘PyCObject_Check’ build/python3_rpy/rpy/rinterface/sexp.c:264:3: warning: implicit declaration of function ‘PyCObject_AsVoidPtr’ In file included from build/python3_rpy/rpy/rinterface/rinterface.c:110:0: build/python3_rpy/rpy/rinterface/array.c: In function ‘array_struct_get’: build/python3_rpy/rpy/rinterface/array.c:164:3: warning: implicit declaration of function ‘PyCObject_FromVoidPtrAndDesc’ build/python3_rpy/rpy/rinterface/array.c:164:3: warning: return makes pointer from integer without a cast

  4. Former user Account Deleted

    just in case, to clarify, it is trunk code of rpy2 from 2.2.0 dev branch, python 3.2b1

  5. Laurent Gautier
    • changed status to new

    Yes, I heard about this Californian company wanting to make the world searchable. I have to try it some day ;-).

    I have not tried with 3.2, and jumped to conclusions from your hint that the problem should be present with Python 2.7 while I could run it without problem on 2.7.

  6. Former user Account Deleted

    my fault, it is just deprecated in python 2.7/3.1, but seems to be removed in python 3.2

    (btw. sorry for no line breaks)

  7. Former user Account Deleted

    it seems like it is not fully fixed

    what about something like

    diff -r 3ccf7d328c47 rpy/rinterface/array.c
    --- a/rpy/rinterface/array.c	Mon Dec 20 20:07:39 2010 +0100
    +++ b/rpy/rinterface/array.c	Wed Dec 22 02:26:11 2010 +0000
    @@ -161,6 +161,10 @@
         return NULL;
       }
       Py_INCREF(self);
    -  return PyCObject_FromVoidPtrAndDesc(inter, self, array_struct_free);
    +#ifdef Py_CAPSULE_H
    +  PyCapsule_New(inter, self, array_struct_free);
    +#else
    +  return PyCObject_FromVoidPtrAndDesc(inter, "rpy2.rinterface._C_API_", array_struct_free);
    +#endif
     }
     
    diff -r 3ccf7d328c47 rpy/rinterface/rexternalptr.c
    --- a/rpy/rinterface/rexternalptr.c	Mon Dec 20 20:07:39 2010 +0100
    +++ b/rpy/rinterface/rexternalptr.c	Wed Dec 22 02:26:11 2010 +0000
    @@ -112,8 +112,14 @@
         return NULL;
       }
       embeddedR_setlock();
    -  PyObject *res = PyCObject_FromVoidPtr(R_ExternalPtrAddr(self->sObj->sexp), 
    +#ifdef Py_CAPSULE_H
    +  PyObject *res = PyCapsule_New((void *)(R_ExternalPtrAddr(self->sObj->sexp)),
    +				"rpy2.rinterface._C_API_",
    +				SexpObject_CObject_destroy);
    +#else
    +  PyObject *res = PyCObject_FromVoidPtr(R_ExternalPtrAddr(self->sObj->sexp),
                                             SexpObject_CObject_destroy);
    +#endif
       embeddedR_freelock();
       return res;
     }
    
    

    (sorry, not real patch as it segfaults)

  8. Laurent Gautier

    Yes. I forget that numpy arrays and R external pointer were also using PyCObjects. Thanks for the patch (although it misses important details when compared to the use of PyCObjects in sexp.c). I have made changes in 9865929a19ad .

    I still do not have Python 3.2 (but now that it is released I should soon have it), and this was tested under Python 2.7.

    Running the full tests under Python 3 is likely to segfault (it does here on Python 3.1). The exact location for the problem remains to be found.

  9. Former user Account Deleted

    thanks for the fix!

    i tried to test it with Python 3.2 beta1, but I am getting

        ValueError: Only Python 2.x and 3.x are supported.
    
  10. Log in to comment