Title: Inconsistent platform support for taking the loaded `libpython` path into account in `getpath` · Issue #127970 · python/cpython · GitHub
Open Graph Title: Inconsistent platform support for taking the loaded `libpython` path into account in `getpath` · Issue #127970 · python/cpython
X Title: Inconsistent platform support for taking the loaded `libpython` path into account in `getpath` · Issue #127970 · python/cpython
Description: Bug report Bug description: The current getpath.py code tries determining base_prefix/base_exec_prefix by searching the location of the libpython library loaded in the current process, falling back to the location of the Python interpret...
Open Graph Description: Bug report Bug description: The current getpath.py code tries determining base_prefix/base_exec_prefix by searching the location of the libpython library loaded in the current process, falling back...
X Description: Bug report Bug description: The current getpath.py code tries determining base_prefix/base_exec_prefix by searching the location of the libpython library loaded in the current process, falling back...
Opengraph URL: https://github.com/python/cpython/issues/127970
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent platform support for taking the loaded `libpython` path into account in `getpath`","articleBody":"# Bug report\n\n### Bug description:\n\nThe current `getpath.py` code tries determining `base_prefix`/`base_exec_prefix` by searching the location of the `libpython` library loaded in the current process, falling back to the location of the Python interpreter executable.\n\nhttps://github.com/python/cpython/blob/7900a85019457c14e8c6abac532846bc9f26760d/Modules/getpath.py#L559-L594\n\nLooking at the location of the `libpython` library in use first makes sense, as that is more reliable than looking at interpreter location — it works when embedding, where there isn't any interpreter executable, it works when the executable is not on `base_prefix`, etc. However, this is only currently supported on Windows and macOS framework builds.\n\nhttps://github.com/python/cpython/blob/7b8bd3b2b81f4aca63c5b603b56998f6b3ee2611/Modules/getpath.c#L802-L837\n\nThe spotty platform support stroke me as odd, especially on macOS, as I see no apparent reason for only supporting framework builds, so I looked traced back the origin of this code.\n\nThe macOS logic goes back to Python 2.0, having been introduced in 54ecc3d24f52ae45ca54a24167e434915c88b60f. At this time, we were determining `base_prefix`/`base_exec_prefix` based on the Python interpreter location, which was problematic on [OS X Frameworks](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html), as the Python interpreter is provided via a launcher. The comment traces back to 55070f5d966f09256c603c3a82fab9b034430c6f and is unrelated to the change made by that commit, it just highlights the special case for macOS framework builds.\n\nIn GH-29041, which introduced `getpath.py`, rewriting the old path initialization C code in Python, the logic changed to purposefully search the `libpython` location before the executable location, also adding Windows support. I imagine the existing macOS code was kept as-is as a mistake, leaving it behind the `WITH_NEXT_FRAMEWORK` flag, maybe under the assumption it was needed for some reason.\n\nConsidering the clear intent in the code, I am treating this a bug.\n\ncc @zooba\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-127972\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/FFY00","@type":"Person","name":"FFY00"},"datePublished":"2024-12-15T18:19:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/127970/cpython/issues/127970"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:629c8358-64ed-5687-70af-a264c304186c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC32:3C7A3:255A0AF:33EB4E5:6A4F5008 |
| html-safe-nonce | eff3d67a1382e359de0a6a357f4800b02916638cd843417e29168cb9ad2bf2f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzMyOjNDN0EzOjI1NUEwQUY6MzNFQjRFNTo2QTRGNTAwOCIsInZpc2l0b3JfaWQiOiI0MDkwMzg0ODg0MzUwMDEzNDQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2d6c5e5b484cc6b0bd657f0242f3ac5bf4c917112e28c23b8768e67529baacbd |
| hovercard-subject-tag | issue:2740806219 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/127970/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55812ce171ca83106d17c13d2cf102ed8e751d64258db3f067560718fb969f57/python/cpython/issues/127970 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55812ce171ca83106d17c13d2cf102ed8e751d64258db3f067560718fb969f57/python/cpython/issues/127970 |
| og:image:alt | Bug report Bug description: The current getpath.py code tries determining base_prefix/base_exec_prefix by searching the location of the libpython library loaded in the current process, falling back... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FFY00 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width