Questions tagged [cythonize]

Use this tag for questions about the compilation of python extension modules based on cython using "cythonize". Use the more generic [cython] tag if the question isn't about the actual compilation process.

The cythonize function can be imported from Cython.Build and is used to compile extensions for python. It is responsible for compiling the .pyx (cython files) to .c files.

The cython "Compilation" documentation contains several examples how to include cythonize in the build process for python modules.

342 questions
20
votes
2 answers

Compiling cython's HelloWorld Example: don't know how to compile C/C++ code on platform

Whenever I try to compile the simpleset cython example helloworld.pyx print "Hello World" setup.py from distutils.core import setup from Cython.Build import cythonize setup( ext_modules = cythonize("helloworld.pyx") ) I am receiving c:\>…
Shaki
  • 349
  • 3
  • 8
16
votes
2 answers

Cython: How to print without GIL

How should I use print in a Cython function with no gil? For example: from libc.math cimport log, fabs cpdef double f(double a, double b) nogil: cdef double c = log( fabs(a - b) ) print c return c gives this error when compiling: Error…
Behzad Jamali
  • 884
  • 2
  • 10
  • 23
15
votes
1 answer

How to apply decorators to Cython cpdef functions

I've been playing around with Cython lately and I came across this error when applying a decorator to a Cython function Cdef functions/classes cannot take arbitrary decorators Here is the code I was tinkering with: import functools def memoize(f): …
Stephen
  • 2,613
  • 1
  • 24
  • 42
12
votes
3 answers

How to use annotate=True on Cythonize()

I'm new to Cython, but got it working by following this basic guide from the official docs: All it says is: "Cython has a way to visualise where interaction with Python objects and Python’s C-API is taking place. For this, pass the annotate=True…
Bruce Nielson
  • 753
  • 8
  • 23
8
votes
2 answers

I get a AttributeError: module 'collections' has no attribute 'Iterable' when I try to install libraries using PIP

I just installed python3 on my new pc and tried to install some libraries (numpy, cython, cymem) using pip and I get AttributeError: module 'collections' has no attribute 'Iterable' but libraries like nltk and cytest installed okay
Saugat Timilsina
  • 91
  • 1
  • 1
  • 6
8
votes
3 answers

PyBind - Overloaded functions

Firstly, my thanks to all of you for trying to resolve this doubt of mine. I am working on converting a minimal C++ project to be used in Python. The real reason behind this effort is for speed. I came across PyBind and was quite surprised at its…
8
votes
1 answer

Cython compilation error "Not allowed in a constant expression"

The following cimport cython @cython.boundscheck(False) def boundtest(): cdef int r=4 cdef double l[3] works fine. But when I try this: cimport cython @cython.boundscheck(False) def boundtest(): cdef int r=4 cdef double…
Takoda
  • 354
  • 3
  • 12
7
votes
1 answer

Cython compiler directive language_level not respected

I am working with compiler directives for Cython (http://docs.cython.org/en/latest/src/reference/compilation.html#globally). $ cat temp.pyx # cython: language_level=3 print("abc", "def", sep=" ,") # invalid in python 2 Compiling: $ cythonize -i…
Saim Raza
  • 1,420
  • 13
  • 16
7
votes
1 answer

Returning a complex object containing PyObject from c++ function Cython

I am trying to wrap some C++ classes and functions to Python using Cython. So far I have wrapped 2 classes, and now I want to wrap a function. The function's signature is std::map> analyze(PyObject* img,…
J. Doe
  • 71
  • 2
6
votes
3 answers

How to use a different C++ compiler in Cython?

I'm working on a project to call C++ from Python. We use Cython for this purpose. When compile by using the command "python3.6 setup.py build_ext --inplace", the compiler "x86_64-linux-gnu-gcc" is used. Is there a way to use a different compiler…
user1556331
  • 345
  • 2
  • 12
6
votes
2 answers

Cython Link Errors for OSX

I have a very similar issue to this SO post; however, after implementing the proposed fix there - I still get the below error. I'm trying to compile a C file that's been generated by Cython. cython ConnectFour.pyx --embed I try to compile my c file…
ptk
  • 6,835
  • 14
  • 45
  • 91
6
votes
2 answers

Cython compilation appends text to filename, how to get rid of it?

I'm working with cython on the Ubuntu platform. Everything works fine, except there is one thing that annoys me. When compiling a cython project to a .so file, the filename of the .pyx file is appended with "cpython-36m-x86_64-linux-gnu". For…
6
votes
0 answers

Cython, how to include 'external' modules and compile a single library?

I have created a plugin for a software, this plugin is written in Python and I wish to distribute it in the form of a shared library (.so) for Mac OS (only). In my code I have a number of imports to packages that may not be installed in the 'target'…
Kostas
  • 367
  • 1
  • 3
  • 17
6
votes
2 answers

How to perform cython files compilation in parallel?

I would like to perform cython files compilation in parallel. So, I take a look at Cython.Build source file, and find the following signature for cythonize function: def cythonize(module_list, exclude=None, nthreads=0, aliases=None, …
Axel Borja
  • 3,718
  • 7
  • 36
  • 50
5
votes
1 answer

Using clang with Cython

I coerced Cython to use clang by specifying the CC environment variable: import os os.environ['CC'] = 'clang' I have a standard build: EXT_MODULES = [Extension('example.src.ex', sources=['example/src/ex.pyx'])] setup_info…
Katie
  • 918
  • 1
  • 5
  • 18
1
2 3
22 23