335 questions
7
votes
1
answer
2k
views
Differences between Cython, extending C/C++ with Python.h, etc
Right now I have an image processing algorithm that is roughly 100 lines or so in Python. It takes about 500ms using numpy, PIL and scipy. I am looking to get it faster, and as the actual algorithm ...
1
vote
0
answers
232
views
How to add another .i swig file to an Extension?
I have created a Python interface to my library using SWIG. This Python interface uses numpy. All of this works correctly.
Now, I want to package this Python interface into a Python wheel. Packaging ...
10
votes
1
answer
2k
views
How to deal with uint8_t on a Python Extension?
I would like to pass as argument of a function in my C module an array of uint8_t's.
I couldn't find a method to directly parse this array, so I'm parsing it to a PyObject_t and then iterating as a ...
0
votes
1
answer
383
views
How to create and return a function object in a c extension module?
I am trying to write a python extension module where some of the functions are curried, but I am not quite sure how to go about doing so. The main difficulty being that I am not sure how to create and ...
0
votes
1
answer
379
views
Equivalent of python lambda function for C (Python Extensions)
I'v written a Python extension module with C to speed up computation times. The first step is a 2D integration of a function f(x,y,k), which is very fast and allows me to integrate over y in [y1(x),y2(...
1
vote
0
answers
705
views
Cannot install matplotlib: "relocation R_X86_64_32S against '_Py_NotImplementedStruct' can not be used when making a shared object"
The command pip install matplotlib in a virtualenv fails with:
g++ -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro build/temp.linux-x86_64-3.5/src/ft2font.o build/temp.linux-x86_64-3.5/...
1
vote
1
answer
3k
views
python/django-extensions ImportError: No module named common.types_
I have managed to run a simple script located in a 'scripts' folder using 'runscript' from django-extensions. The technique is described here [1] (https://django-extensions.readthedocs.org/en/latest/...
3
votes
4
answers
3k
views
Error exporting symbol when building Python C Extension in Windows
I'm working on porting a Python module to Windows. I have a toy example as follows.
The folder structure is:
foo/
libfoo/
foo.c
setup.py
setup.py
from setuptools import setup, Extension
...
2
votes
0
answers
225
views
Crash in boost::python when returning a pointer to llvm::Value
I have a function which returns an llvm::Value*, which I would like to expose to Python. I do not need to expose an interface to llvm::Value; it can be an opaque object in Python.
When I call the ...
2
votes
1
answer
430
views
Trouble importing extension compiled with numpy.distutils
I have a project directory structure:
myproject/
setup.py
myproject/
editors/
....
utilities/
...
find_inf.f90
All the files in the project are python, except for ...
4
votes
2
answers
4k
views
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 ...
3
votes
2
answers
2k
views
How to add an alternative constructor to the target language (specifically Python) in SWIG wrapping C++ code
I am creating Python interfaces to some C++ code that I cannot change, using SWIG. One of the C++ classes has a constructor that creates a partially initialized object that cannot be used as yet, an ...
5
votes
1
answer
5k
views
Unable to compile swig generated wrapper for c++ python extension
Hi I am trying the swig python extension, in c++, example - on an Mit page
My header is - shapes.h
#include <iostream>
class Shape
{
public:
Shape()
{
nshapes++;
}
...
1
vote
0
answers
663
views
Ignore RuntimeWarning: compiletime version 2.6 of module 'extension' does not match runtime version 2.7
After moving to python 2.7, I am getting the following warning:
/opt/python/python-2.7/lib64/python2.7/pkgutil.py:246: RuntimeWarning: compiletime version 2.6 of module 'extension' does not match ...
1
vote
0
answers
149
views
Can't load python extension from installed package
I'm having some problems understanding the importing of a python package with extensions that was installed with setup.py. The packages is 'gmes', and it has 4 extension modules which are .so files.
...
1
vote
0
answers
45
views
Python3 extensions - working with files [duplicate]
I am working on a Python extension module in C++ and I have a FILE object and I want to propagate it Python code so I can work in some way (reading, writing, etc). In Python2 it was possible to use ...
0
votes
0
answers
348
views
Importing python extension module loading already loaded shared library
I am getting an undesired loading of a shared library which has already been loaded.
I have a binary(test_bin) which is supposed to load a shared library(libtest.so).
Also, I have a C python ...
6
votes
2
answers
3k
views
using a C extension in python, without installing it as a module
I am writing C extensions for python. I am just experimenting for the time being and I have written a hello world extension that looks like this :
#include <Python2.7/Python.h>
static ...
0
votes
3
answers
871
views
Passing a float array pointer through a python extension/wrapper – SndObj-library
So I'm feeling that Google is getting tired of trying to help me with this.
I've been trying to experiment some with the SndObj library as of late, and more specifically the python wrapper of it.
...
13
votes
2
answers
6k
views
Storing unsafe C derivative of temporary Python reference error in Cython
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
...
1
vote
1
answer
384
views
Obtain current Python call stack from within SWIG wrapped C++ function
if I call a SWIG-wrapped C/C++ function from Python, is it possible to obtain the current call stack? I would like something similar to the result of ''.join(traceback.format_stack()), but I don't ...
0
votes
0
answers
161
views
How to access the data members in a python class object that was passed to C++? [duplicate]
Say I have a python class object:
class A:
pass
o = A()
o.a=8 # or any data type such as numpy arrays
and I want to pass that python object to C++ extension:
import cpp_lib
cpp_lib.run(o)
...
12
votes
2
answers
8k
views
Can python-C++ extension get a C++ object and call its member function?
I am writing a python/C++ application, that will call methods in C++ extension from python.
Say my C++ has a class:
class A
{
private:
int _i;
public:
A(int i){_i=i;}
...
1
vote
2
answers
608
views
Check if class object is defined in extension module
Given a class object in Python, how can I determine if the class was defined in an extension module (e.g. c, c++, cython), as opposed to being defined in standard python?
inspect.isbuiltin returns ...
0
votes
1
answer
287
views
C Python Extension object type
Is there a way to find out the type of a Python Object in C extension? I need to pass a name(string) or a double value from script to my extension. I thought I could call parsetuple in my extension ...
2
votes
1
answer
115
views
Python module installation fails because the gcc command is missing a flag...that the gcc command has
I am attempting to build a (very simple) Python extension from C code and have run into a snag in the compilation.
(For the record: my C skills are very out-of-date and my code is probably awful.)
...
-1
votes
2
answers
70
views
Why would Python on Windows require using the same version of Microsoft Visual C++ to build native extensions?
Extensions are just dynamic link library, which should not have problem across different version of MSVC.
3
votes
1
answer
3k
views
Can't import module created using SWIG
I'm trying to build python extension. I've create simple library that export single function. It's just a single file - testlib.c that implements function called 'apicall'. Then I create SWIG ...
4
votes
2
answers
741
views
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 ...
60
votes
4
answers
20k
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 -> 1.4, ...
29
votes
2
answers
23k
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:
...
13
votes
2
answers
6k
views
Define Python class from C
I wrapped some C code for Python and it works. The C module creates a handle, which I pass to Python as PyCapsule. The API I would like to have can be made in Python like:
import wrapped
class Test(...
38
votes
2
answers
31k
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++ ...
3
votes
1
answer
233
views
Python C++ extension Singleton
I'm trying to write a C++ extension for Python (3.x) that allows me to use a specific hardware shield for the Raspberry Pi.
I haven't got any experience in writing C and/or C++, but using the ...
0
votes
1
answer
634
views
PyArg_Parse returning frame object instead of PyLongObject
I'm writing a Python Module using the C extension API and am trying to pass a long variable from Python into the C function and then from that get the raw PyLongObject used to represent this variable.
...
0
votes
1
answer
49
views
boost.python built with VC2010
I have successfully built boost.python with visual c++ 2010(dynamic library, 64-bit). I have python 2.7.8 64-bit installed on windows 7 64-bit. I've read here that python extensions should be built ...
1
vote
1
answer
745
views
building python C++ extension -- how to know if a linked library cannot be found
I downloaded a python-wrapped C++ code and am trying to build it from source, and it compiles without errors, but when I run the end result, it fails in a way that seems to suggest that it did not ...
0
votes
1
answer
980
views
Accessing global variables from a python callback of C extension API
I am new to python and C-extensions. I am writing a python code where I have created two threads and have defined a callback function py_cb().
In one thread I am appending to a global list after ...
6
votes
1
answer
3k
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"...
1
vote
1
answer
605
views
Building cython with multiple pyx-files on Windows 8 for python 2.7
To build I use distutils:
python setup.py build_ext --inplace
Building a simple pyx-file works (setup.py):
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules ...
3
votes
1
answer
656
views
Compiling Python extensions with different Visual Studio version
According to the Python documentation, when compiling a Python extension on Windows, "you should use the same version of VC++ that was used to build Python itself". The explanation usually given is ...
0
votes
1
answer
463
views
How to build python extension with Xcode
Request: could someone post a recipe, from top to bottom, for creating an Xcode project that will compile C code to build a Python extension? I've seen several posts here that touch upon the subject,...
4
votes
1
answer
3k
views
What's the difference between tp_clear, tp_dealloc and tp_free?
I have a custom python module for fuzzy string search, implementing Levenshtein distance calculation, it contains a python type, called levtree which has two members a pointer to a wlevtree C type (...
9
votes
3
answers
10k
views
How can I get python.h into my python virtualenv on Mac OSX?
I'm writing a C extension for a python application, and need to test python-specific C code. To do so I need to import Python.h into my C files, but for the life of me I haven't been able to do that. ...
1
vote
1
answer
493
views
Which tool (gdb? xcode? pdb? etc) can I use to find a memory leak in a C-extended python program?
I am writing a python program that includes an extension module written in C. The extension module defines a function that is used in my program continually.
I have a memory leak somewhere in my ...
1
vote
0
answers
158
views
Python windows extensions vcvarsall.bat incorrect windows SDK registry key
I am having a lot of trouble trying to build Python extensions on a particular machine. It has both VS2008 and VS2013 installed along with, what I believe to be, the correct C/C++ libraries, etc. I am ...
1
vote
0
answers
935
views
Python C Extension OpenMP
i am getting a segmentation violation in the python interpreter when trying to access a variable which is returned by my own OpenMP C++ extension.
All the solutions which i have found are either ...
0
votes
1
answer
775
views
How can i declare a Boost.Python C++ Class with PyObjects
i want to write a c++ class with PyObjects to access them from Python to reference them with an existing Python object instance. In short words i want to store/manage Python object instances in the C++...
48
votes
6
answers
91k
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 ...
2
votes
2
answers
3k
views
Passing numpy integer array to c code
I'm trying to write Cython code to dump a dense feature matrix, target vector pair to libsvm format faster than sklearn's built in code. I get a compilation error complaining about a type issue with ...