Skip to content

Relocatable framework for macOS #86680

Description

@gregneagle
BPO 42514
Nosy @ronaldoussoren, @ned-deily, @njsmith, @erlend-aasland, @gregneagle, @tomgoddard, @shakfu, @macmule

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 2020-11-30.18:28:37.873>
labels = ['OS-mac', 'type-feature', '3.11']
title = 'Relocatable framework for macOS'
updated_at = <Date 2022-03-14.13:56:58.762>
user = 'https://github.com/gregneagle'

bugs.python.org fields:

activity = <Date 2022-03-14.13:56:58.762>
actor = 'shakfu'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['macOS']
creation = <Date 2020-11-30.18:28:37.873>
creator = 'gregneagle'
dependencies = []
files = []
hgrepos = []
issue_num = 42514
keywords = []
message_count = 7.0
messages = ['382171', '382173', '382180', '396447', '396772', '396810', '415137']
nosy_count = 8.0
nosy_names = ['ronaldoussoren', 'ned.deily', 'njs', 'erlendaasland', 'gregneagle', 'tomgoddard', 'shakfu', 'macmule']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue42514'
versions = ['Python 3.11']

Activity

  1. gregneagle commented on Nov 30, 2020

    gregneaglemannequin
    MannequinAuthor

    The current Python.framework installed by the macOS packages is hard-coded to /Library/Frameworks/Python.framework and breaks if renamed or moved.

    A relocatable framework would allow users/admins/developers to install a specific framework to an alternate location, or include it inside an application bundle, or access it from a mounted disk image.

    Currently it is possible to use otool and install_name_tool to convert the current framework into one that can be relocated, but doing so breaks any code signing. With Apple Silicon, all executable code and libraries must be code signed, so the effort of relocating the Python framework becomes that more difficult.

    Ideally the official macOS framework would be built as relocatable, eliminating the need to modify it and re-sign it to use it anywhere other than /Library/Frameworks/Python.framework.

  2. ronaldoussoren commented on Nov 30, 2020

    @ronaldoussoren
    Contributor

    There's also macholib (which is used by py2app for rewriting mach-o headers).

    Note that resigning for arm64 is possible using the following command:

    $ codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f <path to mach-O>.

    This was mentioned in the Xcode 12 release notes.

    BTW. My hobby horse w.r.t. a relocatable Python installation is to turn the current framework inside out: have a "Python.app" or "Python 3.10.app" that contains the framework and presents a GUI when double clicked (probably IDLE with some additional menu items). This would simplify the installation experience (no installer, just drop Python.app somewhere convenient).

    I have no idea if I'll ever get around to implementing this.

  3. gregneagle commented on Nov 30, 2020

    gregneaglemannequin
    MannequinAuthor

    A Python.app you could drop somewhere convenient would by definition need a relocatable Python.framework within. :-)

  4. gregneagle commented on Jun 23, 2021

    gregneaglemannequin
    MannequinAuthor

    While checking this issue hoping there might be updates, I realized that I didn't share a link to the script I use to convert python.org's Python framework into one that can be relocated.

    It's here: https://github.com/gregneagle/relocatable-python

  5. macmule commented on Jun 30, 2021

    macmulemannequin
    Mannequin

    Just wondering if any movement on this etc.

    This is something I've been struggling with too, and have attempted to overcome via Greg's project to no avail.

  6. ronaldoussoren commented on Jul 1, 2021

    @ronaldoussoren
    Contributor

    I guess Ned and I are the only core devs that would be vaguely interested in working on this. I have no active plans to work on this.

    Having a relocatable framework would be nice, but doing this in a way that maintains all functionality, esp. w.r.t. the Python executable.

  7. added
    3.11only security fixes
    and removed on Oct 21, 2021
  8. shakfu commented on Mar 14, 2022

    shakfumannequin
    Mannequin

    I have struggled with this exact issue in my py-js project (https://github.com/shakfu/py-js) which embeds a python3 interpreter in a max/msp plugin or in a relocatable folder (package) structure. For the latter case, Greg's solution, which is based on standard methods, has been absolutely crucial. Thank you!

    I have found that trying to do the same with a python distro built with --enable-shared is basically impossible because in this case sys.prefix is hardcoded and it dos not respond (like the framework structure) to the same @rpath methods used by Greg.

    It would be great for those who embed python for a fun or profit to have these issues addressed across all of the standard build structures.

  9. transferred this issue fromon Apr 10, 2022
  10. kevinhendricks commented on Jul 23, 2023

    @kevinhendricks

    FWIW, Sigil the epub editor embeds a relocatable python3 framework inside on macOS but the way to create it involves a lot of manual rpath tweaking and post build changes. Recent _sysconfig_data* and pkg-config files makes it even harder. The version we build and embed suffices for the needs that Sigil has to make python run its plugins.

    See:

    https://github.com/Sigil-Ebook/Sigil/blob/master/docs/Building_A_Relocatable_Python_3.11_Framework_on_MacOSX.txt

    So a way to make things relocatable via the build itself would be quite useful.

  11. johnzhou721 commented on May 2, 2025

    @johnzhou721
    Contributor

    FWIW & FYI: https://github.com/beeware/Python-Apple-support has a Makefile which has a target to build a relocatable for macOS by doing some stuff on the official non-relocatable build.

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

    3.11only security fixesOS-mactype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions