50 questions
Score of 53
1 answer
23004 views
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)
/...
Score of 48
6 answers
91432 views
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 ...
Score of 60
4 answers
20116 views
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 to 1.4, ...
Score of 24
1 answer
8493 views
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 ...
Score of 7
1 answer
3918 views
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....
Score of 6
1 answer
3278 views
creating numpy array in c extension segfaults
I'm just trying to start off by creating a numpy array before I even start to write my extension. Here is a super simple program:
#include <stdio.h>
#include <iostream>
#include "Python.h"...
Score of 50
9 answers
24280 views
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.
...
Score of 29
2 answers
22662 views
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:
...
Score of 2
2 answers
11267 views
"The Pylance server crashed 5 times in the last 3 minutes"? (circa v2023.10.40 of the Pylance VS Code extension)
Every time I launch VS code, the Pylance server crashes 5 times in in 3 minutes, or so the output terminal says. The server stops trying to relaunch and I lose out on a handful of features as a result....
Score of 40
2 answers
43687 views
Aspect oriented programming (AOP) in Python [closed]
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 AspectJ is ...
Score of 38
2 answers
31235 views
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++ ...
Score of 26
3 answers
12560 views
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 ...
Score of 5
5 answers
2005 views
How to create python C++ extension with submodule that can be imported
I'm creating a C++ extension for python. It creates a module parent that contains a sub-module child. The child has one method hello(). It works fine if I call it as
import parent
parent.child.hello()
...
Score of 3
2 answers
9265 views
compile libdnet for python 2.7
I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I ...
Score of 2
1 answer
434 views
Is the import order of extensions in module filenames guaranteed in Python?
Experimentally, I verified that when a compiled extension.pyd (or .so) and plain extension.py both exist in the same directory, the .pyd file gets imported first ; the .py is only imported if the .pyd ...