Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
Questions tagged [python-extensions]
323 questions
3
votes
3 answers
Python's __radd__ doesn't work for C-defined types
When creating a python (2.7.5) extension that defines a noddy.Noddy type with __radd__ method, it gets a different behavior from a (otherwise equivalent) python defined-class object with a custom __radd__ (the former does not work, while the latter…

Thiago Silva
- 155
- 3
3
votes
0 answers
Why does SIGINT sent to Python script kill MySQL connection?
I'm having an issue with sending SIGINT's to python scripts which are connecting to a MySQL database using MySQLdb (mysql-python). The python script runs in an infinite loop, and I want to catch the SIGINT and gracefully exit after completing the…

Chris Palmer
- 193
- 5
3
votes
1 answer
When are the C tp_as_mapping (et al.) methods invoked?
The C PyObject structure contains the fields tp_as_number, tp_as_sequence and tp_as_mapping. In which circumstances are these invoked? Can anybody provide some example Python code which would result in these C methods being called?

isedev
- 18,848
- 3
- 60
- 59
2
votes
3 answers
SWIG interfacing C library to Python (SWIG generated classes are cumbersome to use)
I am using SWIG to generate Python language bindings to my C library. I have managed to build the bindings and exported data structures, but I'm having to jump through some hoops when using the library.
For example the C header has data types and…

Homunculus Reticulli
- 65,167
- 81
- 216
- 341
2
votes
1 answer
Cython built extension fails to export data types and functions
I have just managed to build my first C extension for Python, using Cython to call into an existing C library.
I declared and defined my data types and functions into logical components (following the logical structure of the C library), and I…

Homunculus Reticulli
- 65,167
- 81
- 216
- 341
2
votes
0 answers
Web Scraping using pythn Jupyter Notebook
I have been attempting web scraping, but I encountered an error that states,
"We're sorry but default doesn't work properly without JavaScript enabled. Please enable it to continue."
I have tried enabling JavaScript by using…

shubh jain
- 21
- 1
2
votes
1 answer
Building Python C module on Windows
I am trying to build a 'C' python extension on Windows, the core C code compiles absolutely fine, but I am unable to build the python module using setuptool as I am getting
mandlebrot.c(36): fatal error C1083: Cannot open include file: 'stdio.h': No…

Swatcat
- 73
- 6
- 21
- 57
2
votes
0 answers
Viewing Data in Python Extensions GDB
Suppose I have a class:
class RawMessage(NamedTuple):
data: Dict
timestamp: float
...
The keys and values in this dictionary are probably all integers, but I don't want to state that with certainty.
I additionally hvae a core dump file…

awy
- 43
- 6
2
votes
0 answers
Calling Numpy functions in C++ using Pybind11
After experimenting with Pybind11 to create C++ extensions for Python, I was hoping to write C++ sections for computationally heavy parts of my code. In my particular case, I would like to work with numpy arrays and use a mixture of numpy functions…

stillQuestioning
- 105
- 3
- 10
2
votes
0 answers
Reasons for "Segmentation fault (core dumped)" when using Python extension and FFmpeg
I want to write a Python C extension that includes a function convertVideo() that converts a video from one format to another making use of FFmpeg 3.4.8 (the libav* libaries). The code of the extension is at the end of the question. The extension…

Christian Vorhemus
- 2,396
- 1
- 17
- 29
2
votes
1 answer
How to create Python Stub Files and where to put?
I have a compiled a Python extension.
The resulting binary mylib.so file can be imported in the Python script and works fine.
Now I am wondering how to write the interface stub file mylib.pyi such, that pylint and the Python language server used in…

Matthias
- 1,055
- 2
- 14
- 26
2
votes
1 answer
Convert std::string to PyObject in C++ in Python3
I am trying to convert std::string to PyObject.
std::string st = jsp.updateRoot(people, people);
PyObject* pValue = PyBytes_AsString(st);
It is not working using the above method.
How can I convert?

batuman
- 7,066
- 26
- 107
- 229
2
votes
2 answers
Call `+=` on a PyObject in C++
I'm writing a Python module in C++.
At a certain point, I need to add a PyObject of an arbitrary type to another one. In other words, do the same as a += b would do in Python. But I haven't been able to find a function in the API that does that.
I…

SU3
- 5,064
- 3
- 35
- 66
2
votes
1 answer
How to find minimum versions of python interpreter and libs using CMake
I am building a C extension using pybind11 with CMake. I used to do this with:
find_package(Python3 3.7 REQUIRED)
find_package(PythonLibs 3.7 REQUIRED)
without any issues. Now I need python 3.8 and changed it to:
find_package(PythonInterp 3.8…

Mike
- 3,775
- 8
- 39
- 79
2
votes
0 answers
What is the proper way to structure a Python package with extensions?
Question:
What is the proper way to structure and build a Python wheel with C extensions for deployment? Ideally, the user shouldn't need elevated privileges or be required to point environment variables to the contents of the package.
What I have…

rgmann
- 31
- 2