Skip to content

site.getsitepackages function returns a non-existent path (depending on the prefixes value). #156517

Description

@mbyrnepr2

Bug report

Bug description:

Hi! 👋 My goal was to find the site-packages path for a venv on a machine (a 3rd-party SAST tool at work requires to know the site-packages location).

I'm probably misusing the site.getsitepackages function but nevertheless I thought that it shouldn't return a site-packages path before first checking it exists.

Thank you and have a good one!

import site


print(
    site.getsitepackages(prefixes=["/a/non/existant/venv/path"])
)

['/a/non/existant/venv/path/lib/python3.14/site-packages']

https://docs.python.org/3.15/library/site.html#site.getsitepackages

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions