Skip to content

Deprecation of Py_GetPrefix-family APIs should document the sys.base_* counterparts #125313

Closed

Description

@y5c4l3

Documentation

Documentation suggests sys.prefix as an alternative to Py_GetPrefix in the deprecation note here

Deprecated since version 3.13, will be removed in version 3.15: Get sys.prefix instead.

and it seems correct:

>>> import poc # CPython module that prints `Py_GetPrefix` on init
Prefix: /home/y5/micromamba/envs/py3.13
>>> import sys; print(sys.prefix); print(sys.base_prefix)
/home/y5/micromamba/envs/py3.13
/home/y5/micromamba/envs/py3.13

But strictly speaking, sys.base_prefix is the real counterpart rather than sys.prefix when it involves venv:

# inside venv
>>> import poc
Prefix: /home/y5/micromamba/envs/py3.13
>>> import sys; print(sys.prefix); print(sys.base_prefix)
/tmp/foo
/home/y5/micromamba/envs/py3.13

Source: #125235

Linked PRs

Activity

  1. y5c4l3 commented on Oct 11, 2024

    @y5c4l3
    ContributorAuthor

    A fuller comparison for reference:

    >>> import poc
    ... import sys
    ... for attr in ['executable', 'path', 'prefix', 'base_prefix', 'exec_prefix', 'base_exec_prefix']: print(f'sys.{attr}:', getattr(sys, attr))
    ...
    Py_GetProgramName: python
    Py_GetProgramFullPath: /home/y5/micromamba/envs/py3.13/bin/python
    Py_GetPath: /home/y5/micromamba/envs/py3.13/lib/python313.zip:/home/y5/micromamba/envs/py3.13/lib/python3.13:/home/y5/micromamba/envs/py3.13/lib/python3.13/lib-dynload
    Py_GetPrefix: /home/y5/micromamba/envs/py3.13
    Py_GetExecPrefix: /home/y5/micromamba/envs/py3.13
    sys.executable: /home/y5/micromamba/envs/py3.13/bin/python
    sys.path: ['', '/home/y5/micromamba/envs/py3.13/lib/python313.zip', '/home/y5/micromamba/envs/py3.13/lib/python3.13', '/home/y5/micromamba/envs/py3.13/lib/python3.13/lib-dynload', '/home/y5/micromamba/envs/py3.13/lib/python3.13/site-packages']
    sys.prefix: /home/y5/micromamba/envs/py3.13
    sys.base_prefix: /home/y5/micromamba/envs/py3.13
    sys.exec_prefix: /home/y5/micromamba/envs/py3.13
    sys.base_exec_prefix: /home/y5/micromamba/envs/py3.13
    # inside venv
    >>> import poc
    ... import sys
    ... for attr in ['executable', 'path', 'prefix', 'base_prefix', 'exec_prefix', 'base_exec_prefix']: print(f'sys.{attr}:', getattr(sys, attr))
    ...
    Py_GetProgramName: python
    Py_GetProgramFullPath: /tmp/foo/bin/python
    Py_GetPath: /home/y5/micromamba/envs/py3.13/lib/python313.zip:/home/y5/micromamba/envs/py3.13/lib/python3.13:/home/y5/micromamba/envs/py3.13/lib/python3.13/lib-dynload
    Py_GetPrefix: /home/y5/micromamba/envs/py3.13
    Py_GetExecPrefix: /home/y5/micromamba/envs/py3.13
    sys.executable: /tmp/foo/bin/python
    sys.path: ['', '/home/y5/micromamba/envs/py3.13/lib/python313.zip', '/home/y5/micromamba/envs/py3.13/lib/python3.13', '/home/y5/micromamba/envs/py3.13/lib/python3.13/lib-dynload', '/tmp/foo/lib/python3.13/site-packages']
    sys.prefix: /tmp/foo
    sys.base_prefix: /home/y5/micromamba/envs/py3.13
    sys.exec_prefix: /tmp/foo
    sys.base_exec_prefix: /home/y5/micromamba/envs/py3.13
  2. added a commit that references this issue on Oct 21, 2024
  3. added a commit that references this issue on Oct 21, 2024
  4. vstinner commented on Oct 21, 2024

    @vstinner
    Member

    Fixed by change 7d88140.

  5. added a commit that references this issue on Oct 21, 2024
  6. added a commit that references this issue on Jan 12, 2025
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

    docsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions