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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 24 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Based on a trip down the issue tracker history (notably https://github.com/pypa/pip/issues/4389), I don’t think multiple-runs-with---target was ever an intended use case. Using --prefix is 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 --prefix instead”. If someone wants to add defenses to --target to prevent such usage, let’s file a separate issue for that.

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.