pip: Native namespace package does not install properly when specifying a target directory (-t option)
Description
I cannot make native namespace packages to install properly when specifying a target directory (-t option).
This is important to me as I need to use the the target option to install some packages for an AWS Lambda.
This looks like a very old issue #1924. However I cannot find, after extensive search, any clarification anywhere and the case was closed without apparent resolution.
To confirm I tried it with the pypa samples from pypa/sample-namespace-packages and failed to install both native packages (pkg_a & pkg_b) with an error stating that the directory already exists.
Please note I tried this both on Windows and Linux and the other packaging methods ‘pkgutil’ and ‘pkg_resources’ had the same exact problem.
Thank You
Expected behavior
Both packages pkg_a & pkg_b should install in the same namespace directory.
pip version
21.1.3
Python version
3.8.5
OS
Windows/Linux
How to Reproduce
git clone https://github.com/pypa/sample-namespace-packages
cd sample-namespace-packages/native mkdir temp
pip install ./pkg_a -t temp pip install ./pkg_b -t temp
Output
The second install fails with a message like:
WARNING: Target directory .../sample-namespace-packages/native/temp/example_pkg already exists. Specify --upgrade to force replacement.
Code of Conduct
- I agree to follow the PSF Code of Conduct.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 24 (14 by maintainers)
Commits related to this issue
- Fixing .f12 scripts for python packages There were two problems: 1. The `*` glob pattern was not functioning because of the quotes 2. The `--target` option does not work in combination with namespa... — committed to Checkmk/checkmk by BenediktSeidl 3 years ago
- Use --prefix for pip install It does not reinstall already installed packages https://github.com/pypa/pip/issues/10110#issuecomment-872903406 — committed to kadas-albireo/kadas-albireo2 by m-kuhn 2 years ago
- Ensure only new dependencies are installed - Use --prefix instead of --target for pip install It does not reinstall already installed packages https://github.com/pypa/pip/issues/10110#issuecomment-87... — committed to kadas-albireo/kadas-albireo2 by m-kuhn 2 years ago
Based on a trip down the issue tracker history (notably https://github.com/pypa/pip/issues/4389), I don’t think multiple-runs-with-
--targetwas ever an intended use case. Using--prefixis a much better fit for such uses cases, and I recommend using that.I’ve relabelled this but I’m very much inclined to close this as “no, don’t do that; use
--prefixinstead”. If someone wants to add defenses to--targetto prevent such usage, let’s file a separate issue for that.Well, if you control the Python interpreter and have changed import paths to use --target, then you can also use --prefix instead and use the locations it installs to.
As for the provider of the execution environment being a vendor, I suggest that you take that up with the relevant vendors that they’re using the wrong option for the task at hand and ask on their support channels for help here.
I’m going to just classify it as a bug. Not sure I (or another maintainer) will be able to work on this in the newer future, so any contribution is welcomed.