Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
Questions tagged [python-extensions]
323 questions
4
votes
2 answers
How to return a value from C to python from C's PyObject type of functions?
I was trying to pass a value by calling C file from python and then return that value from C to python again.
My question is how to do this? Can it possible to use return Py_BuildValue(a+b) kind of thing?
#include
static PyObject…

kshitijsoni1
- 43
- 1
- 5
4
votes
2 answers
How should I unit-test python wrapper generated by SWIG
I need to create python wrapper for the library using SWIG and write unit tests for it. I don't know how to do this. My first take on this problem is to mock dynamic library with the same interface as those library that I'm writing wrapper for. This…

Evgeny Lazin
- 9,193
- 6
- 47
- 83
4
votes
0 answers
Sphinx documentation via autodoc for C Python modules
I am trying to document pycurl which is largely a C extension module.
In this extension module there are some classes, written in C. They have methods. The methods have docstrings defined on them:
>>> help(pycurl.Curl().close)
Help on built-in…

user3294948
- 41
- 1
4
votes
1 answer
Conflict between two linux shared objects defining the same function name
My problem deals with Python, Qt, PyQt and other stuff, but the question is actually about how Linux's ld.so actually works.
THE QUESTION
If a program loads two different shared libraries which both have the same entry point name (i.e. they both…

deStrangis
- 1,912
- 1
- 18
- 25
4
votes
2 answers
cross compiling python native C extensions with distutilscross, setup.py won't accept '-x' argument
I have a working cross compile of Python, however I've tried cross compiling the py-smbus extension from i2c-tools using distutilscross and can't get past the command line.
The documentation (https://pypi.python.org/pypi/distutilscross) suggests…

Sparky
- 2,694
- 3
- 21
- 31
4
votes
0 answers
What is the opposite of PyMODINIT_FUNC in Python 2.x C extension modules?
I need to import one of the core modules (datetime) inside my C extension module since I want to return a datetime.date from some functions of my module.
It appears that Python C extension modules have no complement for the PyMODINIT_FUNC upon…

0xC0000022L
- 20,597
- 9
- 86
- 152
4
votes
1 answer
manually building a python extension in cygwin with boost.python
Sorry for such a general title, but i'm not quite sure what exactly i'm missing or what i'm doing wrong. My aim is to build a python extension using boost.python under cygwin and avoiding boost.build tools, that is using make instead of bjam. The…

user938720
- 271
- 3
- 14
4
votes
2 answers
Why I get "C extension could not be compiled" when installing simplejson?
btw, i am using windows, so do i have to install visual studio?
(py) D:\python>pip install simplejson
Downloading/unpacking simplejson
Downloading simplejson-2.6.2.tar.gz (53kB): 53kB downloaded
Running setup.py egg_info for package…

hugemeow
- 7,777
- 13
- 50
- 63
4
votes
2 answers
Can I use ctypes to call back C function from python embedded in C?
I have a C program with embedded python code. I have compiled python 2.7.2 from source and linked my program against libpython2.7.a.
Now in my python code I wish to call back functions from other C libraries linked into my C program. I can write a…

Avner
- 5,791
- 2
- 29
- 33
4
votes
2 answers
Adding output file to Python extension
I've defined a custom build_ext to build a funky extension that I'm trying to make pip-friendly. The following is a trimmed version of what I'm doing.
foo_ext = Extension(
name='foo/_foo',
sources=foo_sources,
)
class MyBuildExt(build_ext):
…

sholsapp
- 15,542
- 10
- 50
- 67
3
votes
1 answer
Monkey patching C extension in Python
Using the method discussed in question 972, I was unable to monkey patch the cursor() method in psycopg:
Tried to patch a methond in psycopg2 with types but it did not work:
>>> import psycopg2, types
import psycopg2, types
>>> db =…

Lester Cheung
- 1,964
- 16
- 17
3
votes
2 answers
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 promise to update the this question too and the scapy…

Fruch
- 408
- 5
- 18
3
votes
3 answers
Error while fetching extension. XHR failed
This is my first time installing and using VSCode, and when I try to install a python extension inside a VSCode application I get the error "Error While fetching extension. XHR failed" . How do I fix it?
image

DonnyDongoran
- 33
- 1
- 1
- 4
3
votes
1 answer
How to define a Python metaclass from C extension?
In pure Python, it is relatively simple to define and use a metaclass.
class Meta(type):
def __new__(cls, name, bases, dict):
x = super().__new__(cls, name, bases, dict)
print("I'm called on class construction time!")
…

Edward Z. Yang
- 26,325
- 16
- 80
- 110
3
votes
0 answers
Accessing a c++ vector/array from python via cython
I am wrapping a c++ program via cython and would like to make a vector from this program available in Python.
I have written a getter method for the vector, which works fine except that it returns a copy of the data:
# in cython
from libcpp.vector…

Samufi
- 2,465
- 3
- 19
- 43