Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Inaccurate caveat regarding ctypes #7035

Closed
memeplex opened this issue Jan 16, 2016 · 8 comments · Fixed by #24133
Closed

DOC: Inaccurate caveat regarding ctypes #7035

memeplex opened this issue Jan 16, 2016 · 8 comments · Fixed by #24133

Comments

@memeplex
Copy link

The "Using python as glue document" states that

There is no standard way in Python distutils to create a standard shared library (an extension module is a “special” shared library Python understands) in a cross-platform manner. Thus, a big disadvantage of ctypes at the time of writing this book is that it is difficult to distribute in a cross-platform manner a Python extension that uses ctypes and includes your own code

But, in fact, build_ext could be used out of the box in most platforms and it's trivial to make it work in Windows. See my answer here. I think something like this recipe could be added to the document in place of the inaccurate and demotivating "big disadvantage" warning.

@rkern
Copy link
Member

rkern commented Jan 16, 2016

Is there a published package that uses this technique?

@memeplex
Copy link
Author

I don't know, I've been using it for a time without problems. There is nothing really special in extension modules besides file naming, initialization and linking against libpython, AFAIK. Most of the built_ext machinery still applies.

@memeplex
Copy link
Author

Besides I don't think there are many published packages using ctypes for custom modules, using this technique or not. Most use cython, swig or extension modules.

@mattip
Copy link
Member

mattip commented May 26, 2019

The document could use an overhaul,

  • updating the section on ctypes with an example
  • adding examples from OpenCV, the deep-learning world, and GnuRadio
  • adding memoryview and cffi as additional ways to interchange buffers

@mattip mattip changed the title Inaccurate caveat regarding ctypes in numpy documentation DOC: Inaccurate caveat regarding ctypes May 26, 2019
@rgommers
Copy link
Member

adding examples from OpenCV, the deep-learning world, and GnuRadio

I'd prefer not to do this part. That belongs in the docs of those packages or a general tutorial, not the numpy docs - just more maintenance for us.

@liang3zy22
Copy link
Contributor

I am working to solve this issue. I have one question. Currently setuptools is mainly used and distutils is legacy. Should the Cython part be updated to setuptools version?

@mattip
Copy link
Member

mattip commented Jul 6, 2023

I am not sure that document belongs in NumPy anymore. It is not really NumPy-specific, and many other tools exist that are not mentioned there: PyO3, nanobind, CFFI. CTypes is largely recognized to be slow and not maintained. Maybe we should just put a note at the top "This was written in 2008 as part of the original Guide to NumPy book by Travis E. Oliphant and may be out of date"

@liang3zy22
Copy link
Contributor

That's right. I will create a PR to add the note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants