Questions tagged [python-extensions]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

323 questions
2
votes
1 answer

Possible to use wide-character members in Python extension objects?

It's simple to create a member for an object in a Python C extension with a base type of char *, using the T_STRING define in the PyMemberDef declaration. Why does there not seem to be an equivalent for wchar_t *? And if there actually is one, what…
JAB
  • 20,783
  • 6
  • 71
  • 80
2
votes
3 answers

How to extend Python and make a C-package?

I embedded and extended Python 2.7 in my C application a while ago. Late on the train I am bringing it to Python 3, and a lot of initializations for the module registration changed for me. Before I used PyModule_Create to create the module and added…
Daniel Stephens
  • 2,371
  • 8
  • 34
  • 86
2
votes
0 answers

Cython .pxd not found after setting language_level parameter or compiler directive

I have a what looks like this in some directory. . ├── Makefile ├── mod │   ├── advancedmath.cpp │   ├── advancedmath.py │   ├── __init__.cpp │   ├── __init__.py │   ├── main.cpp │   ├── main.pxd │   ├── main.pyx │   ├── mathic.pxd │   └──…
axolotl
  • 1,042
  • 1
  • 12
  • 23
2
votes
1 answer

Python extension for Upskirt: garbage at end of string

I've been trying to make a Python extension for Upskirt. I though it would not be too hard for a first C project since there are examples (example program in the Upskirt code and the Ruby extension). The extension works, it converts the Markdown I…
Frank
  • 406
  • 3
  • 9
2
votes
2 answers

INCREF needed when returning argument from Python C Extension function?

This question is pretty simple but will help cement my understanding. I know that arguments to C extension functions are guaranteed to be live references for the duration of the C code (unless manually DECREFed). However, if I have a C extension…
Michael Carilli
  • 371
  • 2
  • 12
2
votes
1 answer

Is the import order of extensions in module filenames guaranteed in Python?

Experimentally, I verified that when a compiled extension.pyd (or .so) and plain extension.py both exist in the same directory, the .pyd file gets imported first ; the .py is only imported if the .pyd file is not found: In [1]: import extension In…
F.X.
  • 6,809
  • 3
  • 49
  • 71
2
votes
1 answer

Compiled boost_python extension fails to import in python 2.7

I am trying to import a python extension coded in c++ with boost. While I experienced some problems compiling the extension using cmake, I managed to do so linked to the boost_python27 library. I then used pythons distutils to install the extension…
mnmldani
  • 53
  • 6
2
votes
1 answer

Import functions from dll (programmed in C++) into Python script when the dll has an embedded Python interpreter

I wrote a library (dll) in c++ that uses an embedded Python interpreter. Executing Python scripts in the embedded interpreter works fine when the library is used by a c++ program. If I call the functions of the dll from a Python program I run into…
siehe-falz
  • 469
  • 3
  • 8
2
votes
0 answers

Extending Python with C on Windows - ImportError: DLL load failed: %1 is not a valid Win32 application

So, I'm interested in communicating between a C program and a Python program so that I can neatly send tasks and data between the two. I figured I'd go ahead and start with this guide. In this guide I have a C file with contents outlined in the…
David Montgomery
  • 473
  • 1
  • 4
  • 15
2
votes
1 answer

How to change function parameter values in a Python 3 C extension?

I can't figure out how to change the value of a parameter passed from Python to C. PyArg_ParseTuple (args, "Os", &file_handle, &filename) will let me get file_handle as a PyObject *. Is there a way to change the value file_handle represents? I…
2
votes
1 answer

Segmentation fault on Python extension method

I have been working on a Python C/C++ extension, I managed to get everything working so far except a method that adds two structures called "int_obj" that have an integer inside and returns a new structure called "add_int_obj". The extension only…
2
votes
2 answers

Python extensions with C: staticforward

So I needed to use the code of the subprocess module to add some functionality I needed. When I was trying to compile the _subprocess.c file, it gives this error message: Error 1 error C2086: 'PyTypeObject sp_handle_type' : redefinition This is…
Omer
  • 456
  • 1
  • 3
  • 19
2
votes
2 answers

Importing a *.pyd library in IronPython's interpreter (ipy.exe)

Following this example, I've created a little hello.pyd library file, the contents of which are at the end of this question. When I enter python interpreter I get the following: D:\test\build\lib.win32-2.6>C:\Python26\python.exe Python 2.6.6…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
2
votes
0 answers

How do I find out if/where xlsxwriter is on my system (for python)?

I am attempting to use the xlsxwriter package to write and image to an eXcel file, but I keep getting the 'No module name 'xlsxwriter' error on the import statement. I am on a closed network, so I am wondering also how I can find out where…
DonB
  • 21
  • 2
2
votes
0 answers

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 function, I get a crash. (I'll provide the stack…
trbabb
  • 1,894
  • 18
  • 35