Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
Questions tagged [python-extensions]
285 questions
52
votes
4 answers
pylint 1.4 reports E1101(no-member) on all C extensions
We've been long-time fans of pylint. Its static analysis has become a critical part of all our python projects and has saved tons of time chasing obscure bugs. But after upgrading from 1.3 -> 1.4, almost all compiled c extensions result in…
![](../../users/profiles/590028.webp)
user590028
- 10,124
- 3
- 30
- 51
48
votes
9 answers
Cython compiled C extension: ImportError: dynamic module does not define init function
I have just compiled part of my C library as an extension using Cython, as a "proof of concept". I managed to hack the code (const correctnes problems etc aside), to finally get an extension built.
However, when I attempted to import the newly…
![](../../users/profiles/962891.webp)
Homunculus Reticulli
- 54,445
- 72
- 197
- 297
46
votes
1 answer
Create an object using Python's C API
Say I have my object layout defined as:
typedef struct {
PyObject_HEAD
// Other stuff...
} pyfoo;
...and my type definition:
static PyTypeObject pyfoo_T = {
PyObject_HEAD_INIT(NULL)
// ...
pyfoo_new,
};
How do I create a new…
![](../../users/profiles/188535.webp)
detly
- 26,649
- 13
- 85
- 142
36
votes
6 answers
Running Cython in Windows x64 - fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
I have been trying to install Cython for Python 2.7 on my Window 7 system. In particular, I prefer everything in 64 bits. (In case you wonder, I need Cython because Cython is one of the components I need for another package for some specialized…
![](../../users/profiles/3181104.webp)
Argyll
- 6,767
- 3
- 19
- 38
30
votes
2 answers
What is a PyObject in Python?
Short version
I recently came across some Python code in which the return type for a function was specified as PyObject in the documentation. What is a PyObject?
Detailed version
I am not a C/C++ programmer, but when I ran into PyObject in the…
![](../../users/profiles/1886357.webp)
eric
- 4,533
- 8
- 49
- 106
28
votes
2 answers
Aspect oriented programming (AOP) in Python
Possible Duplicate:
Any AOP support library for Python?
I am familiar with the AspectJ extension for the Java language.
I want to know if there is such a thing for Python.
Don't get me wrong, I do not mean a library but a language extension like…
![](../../users/profiles/1565284.webp)
coredump
- 2,687
- 5
- 29
- 51
25
votes
4 answers
Tutorials on optimizing non-trivial Python applications with C extensions or Cython
The Python community has published helpful reference material showing how to profile Python code, and the technical details of Python extensions in C or in Cython. I am still searching for tutorials which show, however, for non-trivial Python…
![](../../users/profiles/38140.webp)
gotgenes
- 34,337
- 27
- 93
- 119
25
votes
2 answers
Compiler can't find Py_InitModule() .. is it deprecated and if so what should I use?
I am attempting to write a C extension for python. With the code (below) I get the compiler warning:
implicit declaration of function ‘Py_InitModule’
And it fails at run time with this error:
undefined symbol: Py_InitModule
I have spent literally…
![](../../users/profiles/3940749.webp)
Sam Redway
- 6,145
- 2
- 22
- 35
22
votes
1 answer
How to build a Python C Extension so I can import it from a module
I have a Python project with many sub-modules that I package up with distutils. I would like to build some Python extensions in C to live in some of these sub-modules but I don't understand how to get the Python extension to live in a submodule. …
![](../../users/profiles/42897.webp)
Rich
- 10,547
- 9
- 55
- 87
20
votes
3 answers
How to build and distribute a Python/Cython package that depends on third party libFoo.so
I've written a Python module that depends on some C extensions. Those C extensions depend in turn on several compiled C libraries. I'd like to be able to distribute this module bundled with all the dependencies.
I've put together a minimal example…
![](../../users/profiles/577666.webp)
Sevenless
- 2,645
- 2
- 24
- 46
16
votes
2 answers
Python extension debugging
I'm trying to debug an extension module for python that I wrote in C. I compiled it using the following:
python setup.py build -g install --user
I then debug with:
gdb python
...
b py_node_make
run test.py
It breaks at py_node_make (one of the…
![](../../users/profiles/1695766.webp)
CrazyCasta
- 22,698
- 4
- 38
- 66
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…
![](../../users/profiles/327026.webp)
Mike T
- 34,456
- 15
- 128
- 169
11
votes
2 answers
Method without return value in python c extension module
I'm trying to create a script in python that sends data through a parallel port. I'm creating my own module in C language.
The problem is: when I try to execute my module, python crashes. No errors, no data, nothing. It simply closes.
This is my…
![](../../users/profiles/947194.webp)
markmb
- 802
- 1
- 12
- 31
10
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…
![](../../users/profiles/5680587.webp)
Ansh145
- 359
- 1
- 4
- 10
10
votes
2 answers
Pointers and "Storing unsafe C derivative of temporary Python reference"
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,…
![](../../users/profiles/3121975.webp)
Woody1193
- 3,389
- 1
- 16
- 45