3

I'm trying cython for the first time. Here is what I have.

setup.py

import os
from distutils.core import setup
from Cython.Build import cythonize

os.chdir(os.path.dirname(__file__))
setup(ext_modules = cythonize('example123.pyx'))

example123.pyx

def say_hello(name):
    print(f"Hello {name}")

After setup.py build_ext --inplace I only see example123.c in the folder, no other files created. Searching through all the files didn't provide any results. As far as I know, a .so or .pyd file must have appeared to import into a python script. What may be the problem?

My specs: Windows 7 x64, gcc mingw64, python 3.8, cython 0.29.24

Kaiyakha
  • 1,463
  • 1
  • 6
  • 19
  • You need to use `Extension` from either `setuptools` or `distutils` – Fiver Oct 22 '21 at 16:42
  • @Fiver couldn't you be a bit more specific please? – Kaiyakha Oct 22 '21 at 16:43
  • The accepted answer here is a good start: https://stackoverflow.com/questions/44323474/distutils-core-vs-setuptools-with-c-extension – Fiver Oct 22 '21 at 16:45
  • There is normally a log printed to stdout, telling you what is going on/wrong. There must be an error, e.g. no compiler installed/found. – ead Oct 22 '21 at 16:57
  • 2
    @Fiver, OP’s setup file is straight from cython documentation - this not the problem: https://cython.readthedocs.io/en/latest/src/quickstart/build.html – ead Oct 22 '21 at 16:59
  • @ead yes and that's embarassing – Kaiyakha Oct 22 '21 at 17:02
  • The changing of directories may be the issue – Fiver Oct 22 '21 at 17:04
  • @Fiver it is not, I removed it and checked – Kaiyakha Oct 22 '21 at 17:18
  • I don't think mingw64 is supported/working on any recent version of Python (see https://wiki.python.org/moin/WindowsCompilers) (unless you've built a special version of Python itself with that compiler_. I'd still expect to see an error output though – DavidW Oct 23 '21 at 12:12
  • @DavidW There is no any error in the output, everything is as if the program has terminated successfully – Kaiyakha Oct 24 '21 at 19:54
  • Where are you running `setup.py build_ext --inplace`? I'd expect it to produce some output (whether it's running successfully or not). However, the main point I was making is that I don't think Mingw64 will work at all – DavidW Oct 24 '21 at 20:14
  • I have a similar problem however I can see a file .pyd but not the .so. Any suggestions? @DavidW even with mingw32 it still the same output – sos Sep 26 '22 at 06:03
  • @sos I don't know why you think I have an answer. I was saying "don't use this". I also was not advising that mingw32 worked! – DavidW Sep 26 '22 at 07:10
  • 1
    Maybe look at https://stackoverflow.com/questions/70654722/how-to-create-c-extension-embed-python-with-mingw-w64-on-windows though – DavidW Sep 26 '22 at 07:11

0 Answers0