-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native namespace package does not install properly when specifying a target directory (-t option) #10110
Comments
The warning is suggesting you to use
Can you try it and tell us what happened? |
With --upgrade both packages seem to install fine, but the second install actually replaces the first. Still only one one package installed (pkg_b). tree shows ├───example_pkg |
It is because both packages are being installed on And you can reproduce it as follows: If If you want both packages on [1]: To explain this, imagine a package named |
I do not understand! These are two distinct packages with different names. example_pkg/a example_pkg in this case is not even a package as it is never installed on its own. When doing a local install, pip rightly sees these two as distinct, and they get installed alongside each other which is obviously the intent of using example_pkg as a namespace. One of the ideas of using a target directory is to isolate/segregate a part of a distribution. Instead of installing the packages in [sitepackages] I need them in a folder that is imposed to me by the runtime. I have had no problem installing large distributions of packages in the same target directory, mainly in the context of AWS Lambda Layers. For namespace packages however here it fails. It seems to think example_pkg is a package that needs to be replaced, but there is no such package! Your suggestion that I should create a separate target folder for each package I install is not only extremely cumbersome but it also means I would have to hack the import system to fudge the paths ... |
Well, the container can be named as different, but the inside "folders" are named as the same: It has a simple logic: Imagine an
and an
When these are installed, will be installed into I believe that's why
Anyway, I'm not the best person to explain this 😞. Maybe another pip commiter can take a look on this if you don't understand. |
Any questions or commentaries about this? |
I think the OP's concern is legitimate. But both namespace packages and |
Yeah, that's what I wanted to say since we started to discuss the issue 😆. Thanks @pfmoore.
I think we need more eyes on this. Is there any related label for this? |
Hi @DiddiLeija, Thanks for trying! But sorry to say I have trouble getting at your explanations... First of all there is no need to use --upgrade as these are two different packages. So this already is wrong. What I am asking is why pip cannot do the same thing in the [target] folder as it does in the [sitepackages] folder? This works fine for all packages except namespace packages. The wanted tree structure is easy enough to achieve:
In the same way we get with a local install:
There is nothing magic about it. I could do the copies by hand but I am hoping pip can do the install on my behalf. hi @pfmoore, I understand there are some inner workings that may be complex. However I want to stress how important namespace packages are as a modern distribution pattern and also in the context of customized cloud installs. Thanks |
Yeah... The people doesn't know me as an "explanation expert" 😅. Don't worry.
I understand your concerns. Maybe if we add a |
Hi @DiddiLeija, Thank you! I had a look at the source code to try and better understand ... When using a target directory pip first creates a temporary environment where it installs all the packages in a typical fashion and then copies it back into the target directory, folder by folder. When copying any folder it raises a warning if the folder already exists in the target, regardless of the type of folder, hence the message to use --upgrade. With the --upgrade flag the folder is first erased before copy, without it the copy is skipped. This works for differential installs on most packages but not for namespace packages. For namespace packages the --upgrade flag is no remedy and the warning misleading. One way to make this work reliably, it seems, is to make sure related namespace packages are always bundled in the same install.
This works. Not sure where to take this next. It'd probably be nice to have some clarification or documentation somewhere ... Thanks again |
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. |
Sounds fine. Unfortunately, I will be really busy for these months, so I don't think I would be able to check it. But maybe someone else can take a closer look on this issue. |
Based on a trip down the issue tracker history (notably #4389), I don't think multiple-runs-with- I've relabelled this but I'm very much inclined to close this as "no, don't do that; use |
I agree that the target option does not seem to be designed for multiple runs... The warning message makes it seem so though. However, the use of --prefix does not replace --target exactly here, as the files get installed in a hierarchy several levels below. With target you can simply add the path to the import path and it will work. With prefix you cannot. Also one of the use cases is that the target directory is imposed on the distribution mechanism (eg AWS Lambdas), on a system where you cannot alter the import path... Thanks |
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. |
Got it. Thank You! |
In #4116, I expressed: This issue is still needed and still a blocker to remove the suboptimal hack in pip-run that attempts to do the same thing (jaraco/pip-run#51). Is there a reason the duplicate is left open while this report is closed? It makes it more difficult to track if the issue is a moving target. In that issue and also #5178, I express a use-case where it would be useful if One disadvantage to using prefix is that it creates a lot of unnecessary structure and variability ( I vaguely recall that there were other problems with attempting to use The issues I have are unrelated to namespace packages, but are instead related to desired behaviors around installing with |
I have a long-term goal of making |
I took a stab at this in #12524 |
I don’t think that PR goes in the direction I want. We should never be simply dumping a new install over an old one. Instead, we should properly support the normal uninstall/reinstall mechanism that upgrades use. |
I agree that dumping a new install over an old one isn't ideal by any means. Having said that, my understanding is that |
@pfmoore What about adding the value of In my ideal world |
@pfmoore I've modified my PR, nothing will get overwritten without |
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 namespace packages: pypa/pip#10110 Both problems would have been caught in the first place if this has been thoroughly tested. Sorry. Change-Id: I2e0829cb9fbe160289e7340d79087a62563121a1
It does not reinstall already installed packages pypa/pip#10110 (comment)
- Use --prefix instead of --target for pip install It does not reinstall already installed packages pypa/pip#10110 (comment)
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
Code of Conduct
The text was updated successfully, but these errors were encountered: