Questions tagged [python-extensions]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

323 questions
12
votes
1 answer

Py_BuildValue: make tuple with bool?

I see in docs, that I can build tuple value with int (specifying 'i'). I need to make tuple with bool, e.g. (True, 10). How can I make such tuple with bool (what specifier needed)?
Prog1020
  • 4,530
  • 8
  • 31
  • 65
12
votes
3 answers

Building 64-bit Python extensions with f2py on Windows

I'm attempting to build a Python extension from Fortran source using Numpy's f2py.py script. I'm following the steps from http://www.scipy.org/F2PY_Windows (web archive). My system is Windows 7 64-bit, and I primarily use Python 2.7.3 [MSC v.1500 64…
Mike T
  • 41,085
  • 18
  • 152
  • 203
12
votes
1 answer

What does Cython do with imports?

I want to create a Python extension and I really like the idea of using Cython. Mainly to gain more knowledge about it and to take advantage of speed gains, if any. I have read quite a bit of Cython documentation but I am not a computer scientist…
Phil
  • 13,875
  • 21
  • 81
  • 126
12
votes
1 answer

How to specify docstring for __init__ in Python C extension

Perhaps a stupid question: how can one specify docstring for special functions like __init__ when writing a C extension? For ordinary methods, method table has provision for docstrings. The following autogenerated documentation is displayed when I…
subhacom
  • 868
  • 10
  • 24
11
votes
3 answers

How can I write a C function that takes either an int or a float?

I want to create a function in C that extends Python that can take inputs of either float or int type. So basically, I want f(5) and f(5.5) to be acceptable inputs. I don't think I can use if (!PyArg_ParseTuple(args, "i", $value)) because it only…
ansg191
  • 419
  • 1
  • 7
  • 16
11
votes
2 answers

Storing unsafe C derivative of temporary Python reference error in Cython

I was writing code to store a (potentially) very large integer value into an array of chars referenced by a pointer. My code looks like this: cdef class Variable: cdef unsigned int Length cdef char * Array def __cinit__(self, var,…
Woody1193
  • 7,252
  • 5
  • 40
  • 90
11
votes
2 answers

Can python-C++ extension get a C++ object and call its member function?

I am writing a python/C++ application, that will call methods in C++ extension from python. Say my C++ has a class: class A { private: int _i; public: A(int i){_i=i;} int get_i(){return _i;} } A a=A(); It there…
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117
10
votes
1 answer

How to deal with uint8_t on a Python Extension?

I would like to pass as argument of a function in my C module an array of uint8_t's. I couldn't find a method to directly parse this array, so I'm parsing it to a PyObject_t and then iterating as a PyTuple_t object. This way, I need to cast each…
Pedro Alves
  • 1,667
  • 4
  • 17
  • 37
9
votes
1 answer

How to efficiently build a Python dictionary in C++

For performance reasons I want to port parts of my python program to C++ and I therefore try to write a simple extension for my program. The C++ part will build a dictionary, which then needs to be delivered to the Python program. One way I found…
tobigue
  • 3,557
  • 3
  • 25
  • 29
9
votes
2 answers

Create Python C extension using MacOS 10.15 (Catalina) that is backwards compatible (MacOS10.9+)

How can I create a Python C extension wheel for MacOS that is backwards compatible (MacOS 10.9+) using MacOS 10.15? This is what I have so far: export MACOSX_DEPLOYMENT_TARGET=10.9 python -m pip wheel . -w wheels --no-deps python -m pip install…
AstrOne
  • 3,569
  • 7
  • 32
  • 54
9
votes
3 answers

How can I get python.h into my python virtualenv on Mac OSX?

I'm writing a C extension for a python application, and need to test python-specific C code. To do so I need to import Python.h into my C files, but for the life of me I haven't been able to do that. Most tutorials suggest something along the lines…
Faiyam Rahman
  • 305
  • 2
  • 4
  • 8
9
votes
1 answer

Definition of PyBufferProcs in Python 2.7 when class implements PEP 3118

I am in the process of extending the classes in our library (which supports Python 2.7) to support PEP 3118, which has been back-ported to 2.7. From the documentation, I need to initialize the tp_as_buffer field to point to a PyBufferProcs. From…
James Kanze
  • 150,581
  • 18
  • 184
  • 329
8
votes
1 answer

.so module doesnt import in python: dynamic module does not define init function

I am trying to write a python wrapper for a C function. After writing all the code, and getting it to compile, Python can't import the module. I am following the example given here. I reproduce it here, after fixing some typos. There is a file…
highBandWidth
  • 16,751
  • 20
  • 84
  • 131
7
votes
1 answer

Cython compilation error for free function (Cannot convert Python object argument to type 'FooBar *')

I am using Cython (0.15.2) to create an extension for Python (2.6.5). I have created a pxd file and a pyx file. Here are the contents of my pyx file: cimport capifuncs cdef class myArray: cdef capifuncs.myArray *_my_array def…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
7
votes
1 answer

Including and distributing third party libraries with a Python C extension

I'm building a C Python extension which makes use of a "third party" library— in this case, one that I've built using a separate build process and toolchain. Call this library libplumbus.dylib. Directory structure would be: grumbo/ include/ …
trbabb
  • 1,894
  • 18
  • 35
1
2
3
21 22