On 09. 06. 22 10:35, Matthew Brett wrote:
Hi,

On Wed, Jun 8, 2022 at 7:34 PM <jensa...@soegaard.net> wrote:

Hi All,

Hope this is the right forum.

I am working on using Numpy from the programming language Racket.

My plan of attack is to use Python via `libpython`.
That is, from Racket I use `ffilib` to load `libpython` and from there I use 
the C API
to control Python.

Here is what works at the moment:

1. From Racket I can load `libpython` via `ffilib`.
2. It is possible to initialize a Python process and run Python programs in it.
3. It is possible to import modules written in Python.

What doesn't work is importing `numpy`.

The error I get when I run `import numpy` is:

     ImportError: 
dlopen(/usr/local/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so,
 0x0002):
                           symbol not found in flat namespace 
'_PyBaseObject_Type'

There is some discussion of libpython, embedded interpreters and the
Python namespace symbols here:

https://mail.python.org/pipermail/distutils-sig/2016-February/028275.html

Note that since that mail was written in 2016, Fedora changed to be closer to Debian:

- libpython3.X.so still contains the actual python runtime
- /usr/bin/python3.X still links to libpython to do the actual work
- python extension module packages still depend on the libpython package, but by default now contain extension modules that *ARE NOT* linked against libpython3.X.so - python extension modules compiled locally now *DO NOT* get linked against libpython3.X.so by default (AFAIK)

This means that extension modules get the symbols from the Python runtime that imported them, which means it's possible to use different runtime (like a debug build of Python -- in fact, this change was made after debug builds of Python were made API-compatible with regular builds).

Software that embeds Python (i.e. calls Py_Initialize rather than has PyInit_modulename called) still links to libpython. It does need to use RTLD_GLOBAL with libpython, and can't have multiple Python runtimes in a single process (which does suck for “plugins” that embed Python, like mod_wsgi for the Apache web server).

Does Racket's ffilib support RTLD_GLOBAL?
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to