python-c-extension

Cython package with __init__.pyx: Possible?

Cython package with __init__.pyx: Possible? Question: Is it possible to create a Python 2.7 package using __init__.pyx (compiled to __init__.so)? If so how? I haven’t had any luck getting it to work. Here is what I have tried: setup.py: #!/usr/bin/env python from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext foo = …

Total answers: 2

Passing 3-dimensional numpy array to C

Passing 3-dimensional numpy array to C Question: I’m writing a C extension to my Python program for speed purposes, and running into some very strange behaviour trying to pass in a 3-dimensional numpy array. It works with a 2-dimensional array, but I’m sure I’m screwing something up with the pointers trying to get it to …

Total answers: 4

PyEval_InitThreads in Python 3: How/when to call it? (the saga continues ad nauseam)

PyEval_InitThreads in Python 3: How/when to call it? (the saga continues ad nauseam) Question: Basically there seems to be massive confusion/ambiguity over when exactly PyEval_InitThreads() is supposed to be called, and what accompanying API calls are needed. The official Python documentation is unfortunately very ambiguous. There are already many questions on stackoverflow regarding this topic, …

Total answers: 7

How to make a copy of a python module at runtime?

How to make a copy of a python module at runtime? Question: I need to make a copy of a socket module to be able to use it and to have one more socket module monkey-patched and use it differently. Is this possible? I mean to really copy a module, namely to get the same …

Total answers: 4

Python C Extension – Why are methods that use keyword arguments cast to PyCFunction

Python C Extension – Why are methods that use keyword arguments cast to PyCFunction Question: I’ve am learning about Python-C extensions and am puzzled as to why methods that use keyword arguments must be cast to PyCFunctions. My understanding of a PyCFunction is that it takes two pointers to PyObjects and returns a single pointer …

Total answers: 2

Python C extension: Use extension PYD or DLL?

Python C extension: Use extension PYD or DLL? Question: I have a Python extension written in C and I wonder if I should use the file extension DLL or PYD under Windows. (And what would I use in Linux?) Are there any differences (besides the filename)? I found an unofficial article. Is this the secret …

Total answers: 4

Python and OpenMP C Extensions

Python and OpenMP C Extensions Question: I have a C extension in which I’d like to use OpenMP. When I import my module, though, I get an import error: ImportError: /home/…/_entropysplit.so: undefined symbol: GOMP_parallel_end I’ve compiled the module with -fopenmp and -lgomp. Is this because my Python installation wasn’t compiled with the -fopenmp flag? Will …

Total answers: 3

Building lxml for Python 2.7 on Windows

Building lxml for Python 2.7 on Windows Question: I am trying to build lxml for Python 2.7 on Windows 64 bit machine. I couldn’t find lxml egg for Python 2.7 version. So I am compiling it from sources. I am following instructions on this site http://lxml.de/build.html under static linking section. I am getting error C:Documents …

Total answers: 4

Is it normal that running python under valgrind shows many errors with memory?

Is it normal that running python under valgrind shows many errors with memory? Question: I’ve tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much “noise” in the valgrind output, even if I’ve ran simple command as: valgrind python -c “” Valgrind …

Total answers: 7