delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/09/22/02:39:56

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E06FD385773C
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1695364794;
bh=+evhVzYkAstb6TBONW0Uf8L+YkHz6iX1JR8n4Yo5vJw=;
h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:From;
b=goEorrARpL73LdoCtFPiKfSb4BEfXkRvvrSkvkaDqaGm/MNEvJvSRQ774rW7DSqLe
/GvQDVMvtt2X/T96sWQ5xMtK4pcVznc6V6SyIbPP+/PGvD/EXduzh+U7RqQMZTPn+o
AMjQSewD/A1lQCCGygZmwJiLuXDxvgldTWxJZI9c=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 116513858C3A
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1695364756; x=1695969556;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=rd/fDq9BRzZIjpc3d7HSKI/SyleMti6QtwvVRqxAZ0Y=;
b=FXso+s+VEKTfk8EVyPAbFaoUopWfKM1z5M0ZVFiyAzJnqeifM1wEK9CXfFbTePLnVU
vd9cska+kerCjO6gbpte8uEDT0+dNpQBHYvS3sUiEbleid73JRRj0fzCl0UgsnLsGXz3
zUuniUe3V/GWKgDRYSlQCGE2dRtK/YpwdpNCWZf57fXa9/TU4cFsO0/K09AKlYux3SmJ
OVBZQoHIWtGQOJ8ADehMLBUXZVtwLJfTN4t+UZW0k9UsVcXH8EtRXqJcEavkwKuX5Flr
wreFlyhkGLJaeXvTGURDsXvGpquc0AlvOIEt/TvUTFc4puZgEbJ2qg2xzl6kHt6vcsFH
JG5A==
X-Gm-Message-State: AOJu0Yy0iiyvI+2AIGYqgt0CDukkjQ/dMFtsMr4E4vhKORUfjtdjuBhR
FU/9AgsQ47WcxOdQdd/sz6Aus/ehJl51KCiB4tIE0Pz/+VBj2dVSyuHvJYu3
X-Google-Smtp-Source: AGHT+IHoyqquB6YA0cMIdwHT8pLULPnlXtGZ+Qt/03yYBu+Wvu4DMtdhgOKAE5RqVwlrSLbm7xsq5lARuQ3fRFc8cqY=
X-Received: by 2002:a4a:a54b:0:b0:57b:575f:4f8c with SMTP id
s11-20020a4aa54b000000b0057b575f4f8cmr3344452oom.9.1695364756010; Thu, 21 Sep
2023 23:39:16 -0700 (PDT)
MIME-Version: 1.0
Date: Fri, 22 Sep 2023 12:09:05 +0530
Message-ID: <CAHdXvFqMT3_2XQufPS-jrRYQfKp-U-VPEz=LcdHngc_DwX7kFQ@mail.gmail.com>
Subject: Python C Extension Module loading issue on Cygwin
To: cygwin AT cygwin DOT com
X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS,
TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Mesibo Technical via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Mesibo Technical <technical AT tringme DOT in>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

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!

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019