public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Python C Extension Module loading issue on Cygwin
@ 2023-09-22  6:39 Mesibo Technical
  2023-09-29  6:13 ` jojelino
  2023-11-27 17:49 ` Marco Atzeri
  0 siblings, 2 replies; 4+ messages in thread
From: Mesibo Technical @ 2023-09-22  6:39 UTC (permalink / raw)
  To: cygwin

This issue is about Python on Cygwin not using the recommended module extension.

We have a real-time messaging Python module
(https://pypi.org/project/mesibo/) available on various platforms,
including Linux, macOS, Windows, and Raspberry Pi. It is written in
C/C++ and has been working correctly on these platforms.

Recently, one of our users encountered the "ModuleNotFoundError issue"
when trying to use it on Cygwin.

ModuleNotFoundError: No module named '_mesibo'

Upon investigation, we found that the Python version running on Cygwin
is not using the correct DLL extension as recommended in Python's
official documentation. According to Python's documentation here
https://docs.python.org/3/extending/building.html:

"A C extension for CPython is a shared library (e.g. a .so file on
Linux, .pyd on Windows), which exports an initialization function. To
be importable, the shared library must be available on PYTHONPATH, and
must be named after the module name, with an appropriate extension."

We followed this documentation and used the .pyd extension as
suggested for Windows. It works fine with the Python version bundled
with Windows, and also when downloaded from the Python website.
However, Python on Cygwin seems to be using the .dll extension instead
of .pyd and hence not able to find the module resulting in
ModuleNotFoundError, as you can see from the following logs:

Following are the logs when running the Cygwin version, as you can
see, it is trying to find the module with extension .dll (_mesibo.dll)
instead of .pyd (_mesibo.pyd)

[/cygdrive/c/python] $ python -vvvv test.py
...
# trying /usr/local/lib/python3.9/site-packages/mesibo/_mesibo.cpython-39-x86_64-cygwin.dll
# trying /usr/local/lib/python3.9/site-packages/mesibo/_mesibo.abi3.dll
# trying /usr/local/lib/python3.9/site-packages/mesibo/_mesibo.dll
...

On the contrary, on Python bundle with Windows or when we download and
install from the Python website correctly looks for and loads
_mesibo.pyd

C:\mesibo > python -vvvv test.py
...
# trying
C:\Users\Grace\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\mesibo\_mesibo.cp311-win_amd64.pyd
# trying C:\Users\Grace\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\mesibo\_mesibo.pyd

While we were able to temporarily address this issue by manually
renaming .pyd to .dll for Cygwin, we are skeptical whether this is the
correct and future-proof solution.

Any idea why Cygwin is using the .dll extension instead of the .pyd
extension as recommended by Python's official documentation?
Additionally, is there a way to know during runtime the specific
extension used by a particular version of Python, without having to
make assumptions based on the system type?

Any insights or solutions will be greatly appreciated.

Thanks a lot!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-27 17:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22  6:39 Python C Extension Module loading issue on Cygwin Mesibo Technical
2023-09-29  6:13 ` jojelino
2023-11-27 17:49 ` Marco Atzeri
2023-11-27 17:57   ` Eliot Moss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).