Hi guys. Running into strange python versioning is...
# general
Hi guys. Running into strange python versioning issue when running Dockerfiles. When the Dockerfile has
FROM python:3.8-buster
and somebody runs
./pants run src/${appname}
we get an error saying
/usr/bin/env: 'python3.9': No such file or directory
I do have 3..9 installed locally, but not 3.8. We can fix this error by changing the python version to
FROM python:3.9-buster
. Does pants use your local python install when running docker?
what?? 🙂
That seems very weird
You’re running Pants to build Docker images, or you’re running Pants inside a Docker container?
Hi. Pants to build docker images
@curved-television-6568 ideas?
Seems like the PEX might be built with 3.9 interpreter constraints, but you're building it in a docker image with only 3.8?
(I'm guessing you're running a PEX in the docker image)
yup. pex is in the docker image
^ do you mean these constraints?
Yeah. I think something in the PEX is referencing 3.9 🤔 I'll leave it to people more knowledgeable in PEX 🙂
got it. my coworker and I are using the same constraints. just have different python versions installed
Pants allows you to pick a shebang, you probably want to do that and set
/usr/bin/env python
/usr/bin/env python3
/usr/bin/env python3.8
. Currently you allow ">=3.8,<4" so Pants finds Python 3.9 on your machine, uses it and
/usr/bin/env python3.9
is made the shebang. https://www.pantsbuild.org/docs/reference-pex_binary#codeshebangcode
I think the
in the PEX has a she-bang that might be version-specific by default
@enough-analyst-54434 Interesting. So as a company, we need to make sure all users have the correct python version installed on their machines
I think that solves our problem. I will get back to you in a bit
We should probably encourage repos to - if they can - lock down interpreter constraints to a single Python version
@incalculable-hydrogen-44003 no, you just need to pick a shebang that works with all Pythons. That said, I agree with Benjy - it is definitely most sane to stick to a single version if you're not shipping a consumer app where you need to support variety on their machines (like Pants has to!). This is similar to a certain argument for not using macOS to dev if your production env is Linux.
💯 1
@enough-analyst-54434 Thank you. Is there a way to set the shebang global? Or do I need to use a macro?
Just in case its not clear @incalculable-hydrogen-44003 the shebang is the tricky part here since the OS runs it - nothing Pants, Pex or Python can do. That said, if a python is found by the shebang, any python pretty much - Pex supports ~all Python versions, Pex will re-boot itself and use the correct Python per your interpreter constraints if needed.
I think you need a macro unless your Pants version supports the
target mechanism,
Thanks @enough-analyst-54434. We are currently moving our company to a pants monorepo with a strange setup, and your quick responses have made the process much easier.
But I think this would all be moot if you could change your repo’s interpreter constraints to
or to
or whatever
e.g., pick one interpreter version for everyone to use
It saves a LOT of trouble
this being just one example