python-extensions

Undefined symbol at runtime. Import Python C++ extension

Undefined symbol at runtime. Import Python C++ extension Question: I have a python package (my_python_package), part of which is a C++ extension (my_ext) with a single function (my_ext_func). The extension depends on my C++ library (libmycpp) and my C++ library depends on libarrow. The problem is that I get an error while importing a function …

Total answers: 1

VS Code: "The isort server crashed 5 times in the last 3 minutes…"

VS Code: "The isort server crashed 5 times in the last 3 minutes…" Question: 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 Python …

Total answers: 5

How to generate .pyi files for a compiled Python extension?

How to generate .pyi files for a compiled Python extension? Question: I build a compiled Python extension (.pyd file) with C++ and pybind11. I would like to generate a single Python interface .pyi file for my .pyd file. There are a few similar questions referring to the mypy stubgen module, however, this one produces a …

Total answers: 2

Storing unsafe C derivative of temporary Python reference error in Cython

Storing unsafe C derivative of temporary Python reference error in Cython Question: 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, length): self.Length = …

Total answers: 2

pylint 1.4 reports E1101(no-member) on all C extensions

pylint 1.4 reports E1101(no-member) on all C extensions Question: 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 E1101(no-member) errors. Projects that …

Total answers: 4

Compiler can't find Py_InitModule() .. is it deprecated and if so what should I use?

Compiler can't find Py_InitModule() .. is it deprecated and if so what should I use? Question: 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 …

Total answers: 2

What is a PyObject in Python?

What is a PyObject in Python? Question: 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 documentation linked above, Google …

Total answers: 2

Aspect oriented programming (AOP) in Python

Aspect oriented programming (AOP) in Python Question: 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 AspectJ is …

Total answers: 2

Cython compiled C extension: ImportError: dynamic module does not define init function

Cython compiled C extension: ImportError: dynamic module does not define init function Question: 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 …

Total answers: 9

Create an object using Python's C API

Create an object using Python's C API Question: 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 instance of pyfoo somewhere within my C extension? Asked By: …

Total answers: 1