Hello, How can I generate pex files compatible for...
# general
g
Hello, How can I generate pex files compatible for multiple python version? I generated a pex file but it works only if there exists a python3.10. How can I make it work for lets say python 3.8 and above?
f
Hey Shravan, if you set py3.8 as the
interpreter_constraints
in
pants.toml
, so here maybe something like
Copy code
[python]
interpreter_constraints = ["CPython==3.8.*"]
it'll work for python 3.8 on upwards to 3.11
you need to have python 3.8 available locally
(f.e. with pyenv) edit: with pyenv, without the 'f.e.'
g
can it also detect the environments from conda?
f
ah, good question
no idea 🙂
give it a try I'd suggest
g
Hmmm okay.. I will try to put python interpreter constraints and check
f
but wait, conda isn't providing it's own python binary, is it?
conda is 'just' a pip edit: that was maybe a little unfair to conda, it does a lot more 🙂
g
well if you create a env with conda it downloads a separate python binary along with it.
f
ah ok, didn't know that
h
There’s interpreter constraints settings on the pex binary target.
“3.8 and above” is a lot of variability fwiw
You’ll have a rough time generating lock files for example if you have a large number of dependencies if you use such broad interpreter settings
f
I agree with Nathanael of course - with the intent to support multiple python versions you increase at least your testing needs. here f.e. I've seen
tox
is used (most of the time?) to help with that
g
I have a long way to go I guess. I haven't thought of lock files and testing at all 😅 I need to work on it. I have just generated the pex file and shared it across to my teammates.
Where can I find some best practices for pants projects?
f
I'd recommend to start with the most up-to-date python version possible
it's usually way more easy to just tell your team mates to install python 3.11 for example
and then the journey begins - eventually 3.12 3.13 etc. will appear and if the project still exists you'll have to handle those then anyways
but to start from today with the past is work you can avoid easily if there is no hard requirement for a specific version, but then I'd maybe consider to just go with this particular one
g
Hmmm I need to check with my team why they are still sticking with 3.8..
Otherwise I will stick with one version of python for my project.
f
yes, makes sense. also it might be possible to keep their py3.8 needs while you can still start with 3.11 - pyenv or as you said conda handles multiple versions in parallel on a system
👍 1
g
yup that's one more option.
Thanks for the tip 🙂 @freezing-fall-2672 @high-yak-85899
f
happy to help 👋
🙏 1
e
if you set py3.8 as the interpreter_constraints in pants.toml , so here maybe something like
[python]
interpreter_constraints = ["CPython==3.8.*"]
it'll work for python 3.8 on upwards to 3.11
This is definitely not true. You'd need:
Copy code
[python]
interpreter_constraints = ["CPython>=3.8,<3.12"]
To "work for python 3.8 on upwards to 3.11".