From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by sourceware.org (Postfix) with ESMTPS id 116513858C3A for ; Fri, 22 Sep 2023 06:39:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 116513858C3A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tringme.in Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tringme.in Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-57359e85e9bso904056eaf.2 for ; Thu, 21 Sep 2023 23:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tringme-in.20230601.gappssmtp.com; s=20230601; t=1695364756; x=1695969556; darn=cygwin.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=rd/fDq9BRzZIjpc3d7HSKI/SyleMti6QtwvVRqxAZ0Y=; b=Wm9tCyAb/k4hzAyBZ8MPusuiQ1WN9QXmqGR6aMacGykfPprO58WXJ84PFpNK5/r2ki R1zAeZq0cDGQmsQnTSM6xPb+SeLDHuJv8miMOINc8Q7tFqsqphZlGM6OlIhH3DcXNCoE HirAVnufrBLj5pER6QQ+M5K/GMOr7F6om9CWaLMlVLNDretahk8M+nPTDxYU3kI6jKh5 7EVL/Y+vPZkji9M3S3HOn2IGtKq0QR3ZDwbZIZhc7OHYQVkfHzZYFYSFPGoHqh22nahw XE6MwoG0b/zlRv5f1mAk4O06e0UTfu6gUnvL4I+zbgyb22KBYptk7ebs7WXH7z5CozVM KfUA== 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 From: Mesibo Technical Date: Fri, 22 Sep 2023 12:09:05 +0530 Message-ID: Subject: Python C Extension Module loading issue on Cygwin To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" 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 List-Id: 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!