-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
--use-first-matching-interpreter
shebang doesn't play nicely with macOS Python 3.7 install
#10648
Comments
Preserving the mypex.pex, it has a shebang that references python3.7. macOS installs |
Huh, to confirm, what does Context on what's going on. For "internal" Pexes like |
Nothing since macOS does not install a |
Gr, why Apple for not putting @jsirois @benjyw @stuhood any ideas on how to approach this dilemma with I do expect this problem to come up for other macOS users. -- Tom, two short-term workarounds, neither of which are ideal.
Lines 74 to 78 in d5801ae
|
--use-first-matching-interpreter
shebang doesn't play nicely with macOS Python 3.7 install
https://github.com/pantsbuild/pex/blob/436dc554c1ac234e01529f9f275f7bd01130a51b/pex/interpreter.py#L197-L201 - pex assumes that it can form a binary name of |
I actually think it may be OK to say "Pants requires a binary named |
I agree with the sentiment. The tricky thing is, there is no one specific minor version we know we need. The Pex shebang could be For macOS, it appears that recent installations come with Python 3.7 with a missing binary for -- I am wondering, though, if we could handle |
@benjyw: Adding to Eric's point, this is a "standard" misfeature of macOS and, given the number of users likely on macOS, the more ergonomic design choice is for Pants/PEX to work-around this misfeature itself. The issue to me seems to be that an interpreter is found but instead of using the exact path to that interpreter, |
To further the point, when IntelliJ has me choose a venv for a project, it makes me choose the full path to the interpreter. No guesswork. |
Ohhh @tdyas I really like that suggestion! @benjyw do you see any issue with it? Normally, I'd be afraid it would break speculation, that that interpreter might be available locally but not in the remote environment. But that was always an issue, which we've worked around by marking building a Pex as being Platform specific. That is, the Pex you build locally isn't expected to work on the remote machine to begin with. |
An important thing to remember with |
I recommend Pants/Pex should not assume that the interpreter name is the same in both environments. They are different environments. As an example outside of Pants, Bazel's "toolchain" concept models this and I believe a local toolchain and a remote toolchain could resolve different interpreter names (although worth looking to see how Bazel does Python toolchains). |
The platforms thing alone doesn't solve the issue, except on MacOS (assuming you're not remoting to a MacOS cluster). But you could still get into trouble creating a pex with a full-path shebang on your linux desktop and then trying to use it remotely. But then, that's likely true even now, albeit maybe less often. |
So the benefit of |
I had tried creating that symlink in |
For internal only Pexes, I don't know if we need to care about this, though? For external PEXes like |
And just checked again to verify:
|
We do care about this for internal-only pexes. "system-independent" != "platform-independent". Imagine building a pex locally and then trying to run it on a remoting cluster, or vice versa. With speculation this can easily happen. |
I see - right now we only guard against platform dependence. Hm, well, I think I'd still advocate we go with this precise shebang fix. Speculation is not ready. And this could have very easily been broken already, like you have Py36 on your local machine but Py37 when remoting, and your constraints are >=3.6, so either is fine. |
True, but it's a less aggressive breakage. But yeah, for right now the precise shebang is probably the way to go. I'll put a change up. |
OK so maybe dumb question, but for internal pexes why do we even bother embedding a shebang? What we really want is for pex (to whom we now delegate interpreter selection) to tell us "I selected 3.7", and Pants can then find an appropriate 3.7, depending on platform and invoke the interpreter on the pex. |
I don't follow that. Pants no longer knows how to discover an interpreter. |
But it's the only thing that can, properly, in that it knows where the pex will be running. pex, at build time, does not. |
@tdyas is it possible to put a |
I disagree. The key assumption with For external Pexes, absolutely, it is not safe. Hence not using this optimization. |
Pex should be selecting interpreters, no matter how the PEX was built, by looking at the requested requirement "wheels" embedded in the PEX and what local interpreters are compatible with those wheels and recursing. Everything else is a hack. Granted, we may need to hack if no one thinks they can implement this before I get back in town. |
To be sure I understand how this works in practice: the hack is "use the shebang to bootstrap pex, pex's interpreter selection prioritizes the bootstrapping interpreter if it's compatible, and if we arrange the shebang correctly it will be" ? |
Maybe add an option to |
Catching up with some of the above:
Pex fundamentally assumes its building a deployable; so local machine considerations are not in play. A PEX file has to generally assume it will run on some other machine so it cannot assume information from the current build machine as valid on target runtime machines.
The |
This Pex issue tracks fixing PEX runtime interpreter selection to just use local knowledge of available Pythons and contained distributions: pex-tool/pex#1020. That would solve the problem in this issue by making |
Noting another problem - this time on the Pants side - with using absolute path shebangs related to #10751. If a PEX file gets a statically determined python baked in it becomes a time bomb in the CAS. It will get plucked out to run next week when that interpreter is removed and go boom. The only remedy at that point will be to nuke the local lmdb. It seems in general for local execution that relies on local binaries (not a problem for remote executiuon where images are static) Pants has this problem. We always need to check a cached binary exists and then re-run discovery if it does not before attempting to finally run the desired Process that uses that binary as argv0. In the case of a In the case of PEX files, we could have a rule that uses a |
It only would be picked back out of the cache if the On the original topic of this ticket: can this problematic python install be filtered out by setting:
...which was the solution original proposed on #9760 (which was broken at the time, but should work now that #9760 is resolved)? |
This is false. The |
Since shebangs record information about the host system it is incorrect to ever rely on these when present in a binary stored in the CAS. A shebang that worked in the past can fail in the future even though a viable alternative interpreter may be discoverable. As such, convert all local internal-only PEX creation and execution to using a freshly discovered interpreter. Fixes #10648
This unfortunately is still broken, but in a probably better way.
It seems that |
Oh, John's new script to find the Pex Python might work. It's a Python script. We can add logic to check if we're on |
It would be great if you could add a lot more information about your Mac environment to this ticket since no approach I can see will avoid this error in a principled way. IE a revert may get things working again, but presumably, like before, by sheer luck. |
I have—like most macOS users afaict—two interpreters in
I changed our logging messages for both finding the Bootstrap Interpreter, and finding an interpreter based on interpeter constraints, to log which was chosen. Both were correctly choosing Pants's venv's Py36 interpreter, rather than this busted system interpreter. For good measure, I added this logic to the interpreter discover to avoid using the bad Pythons:
Didn't make a difference, as Pants was choosing the right interpreter from the start. From the above error message, it looks like Pex is for some reason running system Python 3.7 when running Pip. I couldn't figure out why it wasn't using the bootstrap interpreter, i.e. the venv's interpreter. The Process's argv was Afaict, we will want to reland #10779, but either:
|
) This reverts commit ca7e2c2. Unfortunately, this is resulting in Pex using macOS's System Python 3.7 to run Pip, which is botched. This is happening even though Pants is correctly choosing the interpreter and is passing those interpreters to Pex. See #10648 (comment). [ci skip-rust] [ci skip-build-wheels]
Bug is here by inspection: #10779 (comment) |
Am I right that we can close this? |
I think so, yes. |
pants fmt
failure on master as of master plus just some typing changes in #10647 :env: python3.7: No such file or directory
OS is macOS 10.15.6.
which python3
reveals interpreter in a venv that is v3.8.5.The text was updated successfully, but these errors were encountered: