Python Forum
Python C Extension Module loading issue on Cygwin
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python C Extension Module loading issue on Cygwin
#1
We have a real-time messaging Python module 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):

Quote: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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Bulk loading of data using python shivamsvmsri 2 697 Sep-28-2023, 09:04 AM
Last Post: shivamsvmsri
  C Extension module lamer 1 777 Jan-12-2023, 06:01 PM
Last Post: deanhystad
  Mac os (M2) "Python is loading libcrypto in an unsafe way" jpelayo 1 3,664 Sep-22-2022, 08:15 AM
Last Post: jpelayo
  saving and loading text from the clipboard with python program MaartenRo 2 1,668 Jan-22-2022, 05:04 AM
Last Post: MaartenRo
  scan drives in windows from Cygwin RRR 1 1,641 Nov-29-2020, 04:34 PM
Last Post: Larz60+
  Can't open/read txt file in C extension for Python Rad226 8 4,828 Jun-26-2020, 04:08 PM
Last Post: Rad226
  How to make chrome extension in python? Hassibayub 1 2,740 May-06-2020, 04:17 PM
Last Post: DeaD_EyE
  Error in compiling cython extension on Python 3.6.4 on Windows 8 goldenmean 3 5,789 Jun-05-2019, 09:37 PM
Last Post: Larz60+
  Issue In Loading Textblob in jupyter Shivi_Bhatia 1 6,862 Apr-01-2019, 06:50 PM
Last Post: perfringo
  Getting error while loading excel(.xlsx) file using openpyxl module shubhamjainj 1 8,994 Mar-01-2019, 01:05 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020