Skip to content

docs: add example documenting pip install --target#13766

Open
neevets wants to merge 3 commits intopypa:mainfrom
neevets:docs-target-flag
Open

docs: add example documenting pip install --target#13766
neevets wants to merge 3 commits intopypa:mainfrom
neevets:docs-target-flag

Conversation

@neevets
Copy link

@neevets neevets commented Jan 24, 2026

Adds a usage example for the --target flag to improve discoverability.

Fixes #12667

@neevets
Copy link
Author

neevets commented Jan 24, 2026

This PR only updates documentation and does not require a changelog entry.

@notatallshaw notatallshaw added the skip news Does not need a NEWS file entry (eg: trivial changes) label Jan 24, 2026
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this is a bad example. It suggests that --target is suited for installing packages into an existing Python installation, and that isn't the case. The intended use for --target is in embedding scenarios, where you create a brand new, empty directory, and use pip install --target to install requirements into that directory. Your embedded application can then add the directory to the Python interpreter's path.

Using --target to install into an existing site-packages directory may work, but it's very much a "use at your own risk" scenario, and not one that we want to encourage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. I've updated the example to use an initially empty
directory and clarified that the intended use case is embedding scenarios.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a lot better.

I'm still not sure we even want to make the --target option "more discoverable", to be honest. So I'll leave it up to the other maintainers to comment, and decide whether to merge this.

Copy link
Contributor

@henryiii henryiii Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I've used --target for is creating zipapp's: https://github.com/scikit-hep/particle/blob/8ffe2da9151aedf8f15d49a07ccf3401b7815aef/noxfile.py#L55-L91 creates particle.pyz.

Basically you create a dir, install pure Python dependencies with --target, then zip it with python -m zippapp.

@notatallshaw
Copy link
Member

notatallshaw commented Jan 24, 2026

What about keeping the description simple and adding a warning? E.g.

    Install packages into the specified directory instead of the default
    site-packages location.


    .. warning::
    
       The ``--target`` option is intended for specialized scenarios, such as
       embedding Python where a new, empty directory is explicitly added to
       ``sys.path``. Using it for general installation can lead to unexpected
       behavior (for example with namespace packages or upgrades), since
       ``pip`` is designed to install packages into standard environments.

Many users are using --target, so documenting it makes sense, but I think it's a good opportunity to also highlight it can easily lead to unexpected behavior.

@neevets
Copy link
Author

neevets commented Jan 24, 2026

Thanks for the suggestion. I’ve updated the section to keep the description simple and added a warning highlighting the intended use of --target and the potential for unexpected behavior when used outside embedding scenarios.

@notatallshaw
Copy link
Member

I mean, I'm +1 on this approach as I suggested it, but I'm sure other maintainers will have thoughts about the specific wording.

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

Labels

skip news Does not need a NEWS file entry (eg: trivial changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

there is very little documetation for the --target flag

4 participants

Comments