https://pantsbuild.org/ logo
#general
Title
# general
i

incalculable-hydrogen-44003

08/25/2022, 3:49 PM
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

happy-kitchen-89482

08/25/2022, 3:56 PM
huh
what?? 🙂
That seems very weird
You’re running Pants to build Docker images, or you’re running Pants inside a Docker container?
i

incalculable-hydrogen-44003

08/25/2022, 3:57 PM
Hi. Pants to build docker images
image.png
h

happy-kitchen-89482

08/25/2022, 4:15 PM
@curved-television-6568 ideas?
b

bitter-ability-32190

08/25/2022, 4:17 PM
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

incalculable-hydrogen-44003

08/25/2022, 4:17 PM
yup. pex is in the docker image
image.png
^ do you mean these constraints?
b

bitter-ability-32190

08/25/2022, 4:18 PM
Yeah. I think something in the PEX is referencing 3.9 🤔 I'll leave it to people more knowledgeable in PEX 🙂
i

incalculable-hydrogen-44003

08/25/2022, 4:20 PM
got it. my coworker and I are using the same constraints. just have different python versions installed
e

enough-analyst-54434

08/25/2022, 4:21 PM
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

bitter-ability-32190

08/25/2022, 4:21 PM
I think the
__main__.py
in the PEX has a she-bang that might be version-specific by default
coke
i

incalculable-hydrogen-44003

08/25/2022, 4:26 PM
@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

happy-kitchen-89482

08/25/2022, 4:36 PM
We should probably encourage repos to - if they can - lock down interpreter constraints to a single Python version
e

enough-analyst-54434

08/25/2022, 4:38 PM
@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

incalculable-hydrogen-44003

08/25/2022, 4:41 PM
@enough-analyst-54434 Thank you. Is there a way to set the shebang global? Or do I need to use a macro?
e

enough-analyst-54434

08/25/2022, 4:42 PM
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

incalculable-hydrogen-44003

08/25/2022, 4:43 PM
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

happy-kitchen-89482

08/25/2022, 5:25 PM
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
6 Views