GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — import ctypes fails with a statically linked interpreter due to dlopen() failure · Issue #81241 · python/cpython

import ctypes fails with a statically linked interpreter due to dlopen() failure #81241

New issue
Copy link
New issue
Copy link
Closed
Closed
import ctypes fails with a statically linked interpreter due to dlopen() failure#81241
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

indygreg
mannequin
opened on May 27, 2019
Issue body actions
BPO 37060
Nosy @indygreg

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2019-05-27.00:02:41.529>
labels = ['ctypes', '3.7']
title = 'import ctypes fails with a statically linked interpreter due to dlopen() failure'
updated_at = <Date 2019-05-27.00:02:41.529>
user = 'https://github.com/indygreg'

bugs.python.org fields:

activity = <Date 2019-05-27.00:02:41.529>
actor = 'indygreg'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['ctypes']
creation = <Date 2019-05-27.00:02:41.529>
creator = 'indygreg'
dependencies = []
files = []
hgrepos = []
issue_num = 37060
keywords = []
message_count = 1.0
messages = ['343588']
nosy_count = 1.0
nosy_names = ['indygreg']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue37060'
versions = ['Python 3.7']

Linked PRs

  • gh-81241: Fix importing ctypes from statically linked interpreters #153890
  • [3.13] gh-81241: Fix importing ctypes from statically linked interpreters (GH-153890) #158306
  • [3.15] gh-81241: Fix importing ctypes from statically linked interpreters (GH-153890) #158307
  • [3.14] gh-81241: Fix importing ctypes from statically linked interpreters (GH-153890) #158308

Activity

  1. indygreg commented on May 27, 2019

    @indygreg
    indygregmannequin
    on May 27, 2019
    MannequinAuthor
    More actions

    ctypes/__init__.py calls _ctypes.dlopen(None) on Linux as part of code execution during module import. Unfortunately, dlopen() doesn't work if the current executable isn't a dynamic executable.

    Using a fully statically linked Python executable:

    $ ldd python3.7
            not a dynamic executable
    $ python3.7
    >>> import _ctypes
    
    >>> _ctypes.dlopen(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: Dynamic loading not supported
    
    >>> import ctypes
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/gps/src/python-build-standalone.git/build/python/install/lib/python3.7/ctypes/__init__.py", line 444, in <module>
        pythonapi = PyDLL(None)
      File "/home/gps/src/python-build-standalone.git/build/python/install/lib/python3.7/ctypes/__init__.py", line 356, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: Dynamic loading not supported

    I think it is a bug that import ctypes raises OSError at import time in this environment. I can make a compelling argument that this error should either be suppressed or converted to an ImportError.

    Producing a fully statically linked Python executable is a bit of work and isn't easily accomplished with the existing build system. My "python-build-standalone" project automates the process. A fully statically linked Python executable is available in the zstd compressed archive at https://github.com/indygreg/python-build-standalone/releases/download/20190505/cpython-3.7.3-linux64-musl-20190526T0219.tar.zst under the python/install/bin/python3.7 path. Simply extract that archive and run that binary to reproduce.

  2. indygreg
    added
    3.7 (EOL)end of lifeend of life
    topic-ctypes
    on May 27, 2019
  3. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  4. voltagex commented on May 27, 2023

    @voltagex
    voltagex
    on May 27, 2023
    More actions

    @indygreg did you work out a way around this? I note your https://github.com/indygreg/python-build-standalone/blob/main/cpython-unix/patch-ctypes-static-binary.patch, but this does not seem to fix a static build of Python on its own.

  5. serhiy-storchaka
    added this to Ctypes issueson Jan 1, 2024
  6. zanieb
    removed
    3.7 (EOL)end of lifeend of life
    on Nov 26, 2025
  7. zanieb commented on Nov 26, 2025

    @zanieb
    zanieb
    on Nov 26, 2025
    Contributor
    More actions

    I think this issue is still relevant on 3.15+

    cpython/Lib/ctypes/__init__.py

    Line 559 in 7f371ed

    pythonapi = PyDLL(None)

  8. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Jan 24, 2026
  9. ZeroIntensity
    added a commit that references this issue on Sep 28, 2026

    gh-81241: Fix importing `ctypes` from statically linked interpreters (G…

    5637f4e
  10. ZeroIntensity commented on Sep 28, 2026

    @ZeroIntensity
    ZeroIntensity
    on Sep 28, 2026
    Member
    More actions

    Backports are on auto-merge, and the 3.15 backport will be merged separately.

  11. ZeroIntensity
    closed this as completedon Sep 28, 2026
  12. github-project-automation
    moved this to Done in Ctypes issueson Sep 28, 2026
  13. ZeroIntensity
    added 2 commits that reference this issue on Sep 28, 2026

    [3.13] gh-81241: Fix importing `ctypes` from statically linked interp…

    e3d8d3b

    [3.14] gh-81241: Fix importing `ctypes` from statically linked interp…

    24ddd48
  14. serhiy-storchaka
    added a commit that references this issue on Oct 10, 2026

    [3.15] gh-81241: Fix importing `ctypes` from statically linked interp…

    3440ff9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Ctypes issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.