public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mesibo Technical <technical@tringme.in>
To: cygwin@cygwin.com
Subject: Python C Extension Module loading issue on Cygwin
Date: Fri, 22 Sep 2023 12:09:05 +0530	[thread overview]
Message-ID: <CAHdXvFqMT3_2XQufPS-jrRYQfKp-U-VPEz=LcdHngc_DwX7kFQ@mail.gmail.com> (raw)

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!

             reply	other threads:[~2023-09-22  6:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22  6:39 Mesibo Technical [this message]
2023-09-29  6:13 ` jojelino
2023-11-27 17:49 ` Marco Atzeri
2023-11-27 17:57   ` Eliot Moss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHdXvFqMT3_2XQufPS-jrRYQfKp-U-VPEz=LcdHngc_DwX7kFQ@mail.gmail.com' \
    --to=technical@tringme.in \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).