Hi guys. Running into strange python versioning is...
# general
i
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?
h
huh
what?? 🙂
That seems very weird
You’re running Pants to build Docker images, or you’re running Pants inside a Docker container?
i
Hi. Pants to build docker images
image.png
h
@curved-television-6568 ideas?
b
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)
i
yup. pex is in the docker image
image.png
^ do you mean these constraints?
b
Yeah. I think something in the PEX is referencing 3.9 🤔 I'll leave it to people more knowledgeable in PEX 🙂
i
got it. my coworker and I are using the same constraints. just have different python versions installed
e
Pants allows you to pick a shebang, you probably want to do that and set
/usr/bin/env python
or
/usr/bin/env python3
or
/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
b
I think the
__main__.py
in the PEX has a she-bang that might be version-specific by default
coke
i
@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
h
We should probably encourage repos to - if they can - lock down interpreter constraints to a single Python version
e
@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
i
@enough-analyst-54434 Thank you. Is there a way to set the shebang global? Or do I need to use a macro?
e
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
__defaults__
target mechanism,
i
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.
h
But I think this would all be moot if you could change your repo’s interpreter constraints to
">=3.8,<3.9"
or to
">=3.9,<3.10"
or whatever
e.g., pick one interpreter version for everyone to use
It saves a LOT of trouble
this being just one example