swig

swig no module named _example

南笙酒味 提交于 2019-12-03 13:28:33
I cannot reproduce the basic SWIG example on windows. My error is stated in the SWIG docs and I am sure that I do the 2 fixes they mention. For this error: >>> import example Traceback (most recent call last): File "<stdin>", line 1, in ? File "example.py", line 2, in ? import _example ImportError: No module named _example the SWIG documentation clearly states: forget the leading underscore (_). forget the leading underscore (_).> If you get this message, it means that you either forgot to compile the wrapper code into an extension module or you didn't give the extension module the right name.

A trivial Python SWIG error question

假如想象 提交于 2019-12-03 13:02:32
I am trying to get Python running with swig to do C/C++. I am running the tutorial here , 'building a python module'. When I do the call gcc -c example.c example_wrap.c -I /my_correct_path/python2.5 I get an error: my_correct_path/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." example_wrap.c: In function 'SWIG_Python_ConvertFunctionPtr': example_wrap.c:2034: warning: initialization discards qualifiers from pointer target type example_wrap.c: In function 'SWIG_Python_FixMethods': example_wrap.c:3232: warning: initialization

C to Python via SWIG: can't get void** parameters to hold their value

杀马特。学长 韩版系。学妹 提交于 2019-12-03 12:57:52
问题 I have a C interface that looks like this (simplified): extern bool Operation(void ** ppData); extern float GetFieldValue(void* pData); extern void Cleanup(p); which is used as follows: void * p = NULL; float theAnswer = 0.0f; if (Operation(&p)) { theAnswer = GetFieldValue(p); Cleanup(p); } You'll note that Operation() allocates the buffer p, that GetFieldValue queries p, and that Cleanup frees p. I don't have any control over the C interface -- that code is widely used elsewhere. I'd like to

How to see C++ function invocations behind the SWIG interface, TensorFlow

こ雲淡風輕ζ 提交于 2019-12-03 12:49:29
I'm working on TensorFlow and I want to know the relationship between each Python function and the correspondent C++ functions behind the SWIG interface. In other words, I want to be able to know exactly which C++ functions are invoked for every line of Python code of my TensorFlow application. I already saw how to debug the Python code here and how to display at which line of code a segmentation fault happens here , but in these ways I'm able to see only where an error is, while instead I want to be able to know every C++ function invocation, even when there are no bugs in the code (At the

Marshaling a Python PIL Image using SWIG

冷暖自知 提交于 2019-12-03 12:47:39
I've got a library that takes in a very simple C image structure: // Represents a one-channel 8-bit image typedef struct simple_image_t { uint32 rows; uint32 cols; uint8 *imgdata; } simple_image; I didn't create this library, nor this structure, so I can't change it. I'm responsible for wrapping this library for python using SWIG. The Python wrapper needs to be able to take in a PIL Image and convert it into this structure. Here's how I'm doing it right now (using a SWIG %inline% ): // Allows python to easily create and initialize this structure simple_image* py_make_simple_image(uint32 width,

javascript extension to use C based APIs(clutter) in a webapp

爱⌒轻易说出口 提交于 2019-12-03 12:17:56
My goal is to use the C libraries to form web apps. I have choosen the way to do that via using "SWIG" tool. The Swig tool requires three things 1) .c file which defines all the functions. 2) .i file also called interface file which is creating the interface to load the APIs wherin I used the extern keyword. 3) APP written in javascript extension (.js file). I used SWIG tool to compile and run this app to verify the .js file has made correctly. The application is running fine on XMING X11 window. On compilation it creates _wrap.o, .o file and libFILENAME.so Now I want to run this app on

Wrapping a C++ class in Python using SWIG

有些话、适合烂在心里 提交于 2019-12-03 12:16:46
example.h : #ifndef EXAMPLE_H #define EXAMPLE_H class Math { public: int pi() const; void pi(int pi); private: int _pi; }; #endif example.cpp : #include "example.h" int Math::pi() const { return this->_pi; } void Math::pi(int pi) { this->_pi = pi; } example.swig : %module example %{ #define SWIG_FILE_WITH_INIT #include "example.h" %} %include "example.h" I then generate the wrappers, "example.py" and "example_wrap.c" using: swig -python example.swig When I try to compile the wrapper class using: g++ -fPIC -c example.cpp example_wrap.c -I/usr/local/include/python2.6/ I get the following error:

Using SWIG with methods that take std::string as a parameter

依然范特西╮ 提交于 2019-12-03 10:07:36
I used SWIG to wrap my c++ class. Some methods have a const std::string& as a parameter. SWIG creates a type called SWIGTYPE_p_std__string however you cannot just pass a normal string for this when invoking the method in c#. The below example is just a modified example that comes with the SWIG package.: public void setName(SWIGTYPE_p_std__string name) { examplePINVOKE.Shape_setName(swigCPtr, SWIGTYPE_p_std__string.getCPtr(name)); if (examplePINVOKE.SWIGPendingException.Pending) throw examplePINVOKE.SWIGPendingException.Retrieve(); } In my interface file I just have: /* File : example.i */

Convert a std::vector to a NumPy array without copying data

丶灬走出姿态 提交于 2019-12-03 10:03:55
问题 I have a C++ library which currently has some methods inside which return a std::vector defined like public: const std::vector<uint32_t>& getValues() const; I'm currently working on wrapping the whole library for Python using SWIG and this is working well so far. SWIG wraps this getValues() function fine such that it returns a Python tuple. The issue is in my Python-side code I want to convert this to a NumPy array. Of course I can do this by: my_array = np.array(my_object.getValues(), dtype=

Wrap C struct with array member for access in python: SWIG? cython? ctypes?

自古美人都是妖i 提交于 2019-12-03 09:16:13
问题 I want to access a C function that returns a struct containing double arrays (where the lengths of these arrays is given by other int members of the struct) from python. The declaration is typedef struct { int dim; int vertices; int quadrature_degree; int polynomial_degree; int ngi; int quadrature_familiy; double *weight; /* 1D: ngi */ double *l; /* 2D: ngi * dim */ double *n; /* 2D: ngi * vertices */ double *dn; /* 3D: ngi * vertices * dim */ } element; extern void get_element(int dim, int