Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
Questions tagged [python-extensions]
323 questions
56
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…

user590028
- 11,364
- 3
- 40
- 57
52
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…

detly
- 29,332
- 18
- 93
- 152
50
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…

Homunculus Reticulli
- 65,167
- 81
- 216
- 341
45
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…

Argyll
- 8,591
- 4
- 25
- 46
36
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…

eric
- 7,142
- 12
- 72
- 138
35
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…

coredump
- 3,017
- 6
- 35
- 53
28
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…

Sam Redway
- 7,605
- 2
- 27
- 41
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…

gotgenes
- 38,661
- 28
- 100
- 128
24
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…

Sevenless
- 2,805
- 4
- 28
- 47
23
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. …

Rich
- 12,068
- 9
- 62
- 94
18
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…

CrazyCasta
- 26,917
- 4
- 45
- 72
15
votes
6 answers
VS Code: "The isort server crashed 5 times in the last 3 minutes..."
I may have messed up some environmental path variables.
I was tinkering around VS Code while learning about Django and virtual environments, and changing the directory path of my Python install. While figuring out how to point VS Code's default…

Nikola da Vinci
- 145
- 1
- 1
- 4
14
votes
1 answer
Defining a Python enum in a C extension - am I doing this right?
I'm working on a Python C extension and I would like to expose a custom enum (as in: a class inheriting from enum.Enum) that would be entirely defined in C.
It turned out to not be a trivial task and the regular mechanism for inheritance using…

Bartosz Golaszewski
- 333
- 1
- 6
12
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…

markmb
- 852
- 4
- 12
- 32
12
votes
2 answers
Define Python class from C
I wrapped some C code for Python and it works. The C module creates a handle, which I pass to Python as PyCapsule. The API I would like to have can be made in Python like:
import wrapped
class Test(object):
def __init__(self, loc ):
…

Lars Hanke
- 614
- 5
- 16