Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,10 @@ These prefabricated library loaders are available:
:c:expr:`int`, which is of course not always the truth, so you have to assign
the correct :attr:`!restype` attribute to use these functions.

.. note::

If the Python interpreter is statically linked, this may be ``None``.

.. audit-event:: ctypes.dlopen name ctypes.LibraryLoader

Loading a library through any of these objects raises an
Expand Down
5 changes: 4 additions & 1 deletion Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,10 @@ def LoadLibrary(self, name):
# These are Unix-like platforms which use a dynamically-linked libpython.
pythonapi = PyDLL(_sysconfig.get_config_var("LDLIBRARY"))
else:
pythonapi = PyDLL(None)
try:
pythonapi = PyDLL(None)
except OSError:
pythonapi = None


if _os.name == "nt":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :exc:`OSError` when importing :mod:`ctypes` from a statically linked
interpreter.
Loading