This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python fails to import .dylib but works when extension is changed to .so
Type: Stage: resolved
Components: macOS Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: etriskgrove, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2021-04-20 19:59 by etriskgrove, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg391473 - (view) Author: Ellis trisk-grove (etriskgrove) Date: 2021-04-20 19:59
This issue is pretty much summed up by the title. Python does manage to import the library and use it however only when the extension is .so otherwise python cannot find it and fails to import.
msg391488 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-04-21 03:09
Can you please give a code snippet of the behavior you believe is incorrect? It is not clear to me what you mean by importing a library.
msg391493 - (view) Author: Ellis trisk-grove (etriskgrove) Date: 2021-04-21 07:01
This is with regards to an python extension written in zig (I believe the same behaviour would occur from C as I am just using Python.h). What happens is when I compile the library on my mac it generates myLibrary.dylib file, when testing with python the following occurs:

    >>> import myLibrary
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'myLibrary'

However when changing the name of myLibrary.dylib to myLibrary.so python manages to import and use it as it should.
msg391577 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-04-22 05:19
Thanks for the clarification. On most platforms other than Windows, Python expects compiled extension modules (usually written in C or C++) to have an extension of .so. This is true as well on macOS. Typically, extension modules are compiled using Python's Distutils, or one of its newer derivatives, which takes care of creating the proper extension module file name. If you are building an extension module with something else, you'll need to ensure that the shared library file name has the expected format. Note that PEP 3149, implemented in Python 3.2, extends the filename extension to include the Python version (although unversioned .so file names are still accepted for compatibility); see https://docs.python.org/3/whatsnew/3.2.html#pep-3149-abi-version-tagged-so-files for more information.

$ python3 -c 'import sysconfig;print(sysconfig.get_config_var("EXT_SUFFIX"))'
.cpython-39-darwin.so
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 88064
2021-04-22 05:19:50ned.deilysetstatus: open -> closed
resolution: not a bug
messages: + msg391577

stage: resolved
2021-04-21 07:01:58etriskgrovesetmessages: + msg391493
2021-04-21 03:09:07ned.deilysetmessages: + msg391488
2021-04-20 19:59:28etriskgrovecreate