Hello everyone, I have just started exploring pant...
# general
q
Hello everyone, I have just started exploring pants, and I have reached a level where I can create BUILD files for an intermediate level project and then create a pex file with "pants package folder/app.py," and it runs perfectly on my computer. However, when I share it with my senior, it does not work on his computer (error message: bash: ./main_app.pex: Permission denied"). So, what is the thing that I might be missing when creating the pex file, or what are the possible reasons? Can anyone guide me here please? And I am excited to see it working perfectly, so any tips will be a big help :)) (The Python interpreter is the same (3.11), and all the packages are installed on both computers.)
h
How are you sharing this file? Does it have executable permissions on the other system?
q
is that we have to mention in our project? like in toml file or anywhere before creating the pex file?
e
No, its automatically built as an executable. Can you share an
ls -l dist/.../main_app.pex
(the path of the result of
pants package ...
?
and all the packages are installed on both computers
Kind of the whole point of a PEX file is that doesn't matter - the PEX contains all the files it needs except only for the Python interpreter.
q
yup the pex file is created and working in my device but not when I share it to someone... Can i share my github repo link, so you can spot any issues?(its a small project only)
e
Well, it would help if you could actually provide the
ls
output to start. Once you have a PEX file, Pants or your repo's use of it don't matter any more.
Also, please provide
head -1 dist/.../main_app.pex
.
q
-rwxr-xr-x 1 jay jay 2232121 Oct 2 17:08 dist/main/main_app.pex
e
Ok, how about the shebang then (the
head ...
command)?
q
#!/usr/bin/env python3.11
e
Ok, Have your boss run
/usr/bin/env python3.11
on their machine and see what happens.
Either they are copying the PEX file weirdly and have lost permission bits (Did you email it or something?) or the actual interpreter on their machine is borked.
👀 1
q
I am sending the file to him through microsoft teams.
e
Oh Jesus.
So, that's it.
q
oops
😅
e
Well, I would step waaaay back if I were you. This is sort of unix 101.
When you transfer a file via email, or other non-command line tools, it will lose permission bits. You need to re-establish those.
Running
chmod +x main_app.pex
on the boss machine is required.
ALternatively
python main_app.pex
q
great 😅 will try this asap when he comes online
e
That will work without perm bits set to executable.
But he should have known that too really!
🥲 1
q
I am actually a intern only, I dont know much things. (wikl remember this thing)
e
If you look back up at what Benjy asked - this is what he was asking.
Ok - gotcha. You have an excuse - sort of. But your boss does not!
q
hehe, thanks for the helppp!!
🤝
That worked perfectly Thanks 😀
one more issue if can guide me is there anything which i can do to solve the error which i get everytime about the symbolink error? like i dont know why its happening as its working perfectly in one project and in another project I am getting a symbolic error..
e
When asking for support in an asynchronous forum like this with people in different time zones, providing crisp clear details is always good. In general, The version of the tool you're using + the exact command line you ran with all its output is a good bare minimum. Human-level conversational phrases like "getting a symbolic error" really give no information at all.
q
ok sorry about that, like when I run any pants command for example (pants fmt main/app.py) it works but (pants fmt::) raises a error Engine traceback: in
fmt
goal IntrinsicError: Failed to read link "/home/jay/Desktop/pants/pants-practice/venv/bin/python": Absolute symlink: "/usr/bin/python3.11" and same for package 114453.29 [ERROR] 1 Exception encountered: Engine traceback: in
package
goal and all these commands work perfectly in another project with same build files same .toml
e
Pants cannot handle absolute symlinks that exist inside the project directory tree. Most projects don't have these; but a common source of them is a venv you've made. Have you made a venv inside the project?
q
yes
e
That's the issue then. You either need to stop doing that or tell Pants to ignore the venv directory.
By default Pants ignores anything in the
.gitignore
file. If the venv dir should in fact be gitignored but you haven't done so, then that is your fix.
How / why do you create the venv inside the project?
q
I thought that is the best practice to keep the venv separate for every project
e
I am pretty extreme here, but "best practice" is a curse word - run away from these things. You either understand why and when a thing is good, or you are lost.
For Pants repos, Pants creates all the venvs you and it need, save for `pants export`'ed ones, but those are exported under
dist/
and this initial setup advice for the Pants repo has you covered: https://www.pantsbuild.org/docs/initial-configuration#update-gitignore
So; you should ~never need to create a venv when using Pants. Unless you have a very specific reason.
q
ok got it, i read about the venv somewhere when going through all the documentation of pants.. but I forgot it
e
Many modern tools create the venvs for you like this. Not just Pants but Poetry, PDM, tox, nox, etc. They follow the "best practice", but they do it for you, you need not do any venv creation manually.
I'm not sure if Python is your 1st language / ecosystem or not, but its unfortunate in this regard. Modern languages tend to have 1 tool to do these things (Go, Rust, Zig, etc...), Python is old and has no official tools to do these things, so there are 18 ways. Very confusing.
q
yup python is my 1st language only, and to summarise so when i initialises pants project every python package i install is installed for that particular project only? sorry if i got it wrrong
e
every python package i install
You install 0 packages. Pants installs them and it does so in many (many, many!!) small, exact fit venvs.
These venvs are all hidden and you never interact with them directly.
q
ohh i will give it a try so I understand it perfectly.
e
I'd say Pants is probably about the worst tool possible for learning the Python ecosystem.
You sort-of have to come into Pants already knowing your language ecosystem. If you don't, Pants may be good for doing day to day work, but you will be mystified how the ecosystem actually works when you step away from Pants. Pants hides everything about the ecosystem for the most part.
q
ohh so I will try to get knowledge of everything which comes in way, i also want to implement pants now on a bigger project!! so there I might also find some new errors😅
e
Well, good luck. There is a lot of good documentation at https://www.pantsbuild.org and sometimes helpful examples in the
example-*
repos: https://github.com/search?q=org%3Apantsbuild+%2Frepo%3Aexample-.*%2F&type=repositories&ref=advsearch
q
nicee so many example repos, I only found 2-3 repos only so, it didnt work out so well in the beginning
Thanks for the help 😁
Hello!! what are the needed changes if i want my pex file to run on cross platform, like i am using ubuntu and i want my pex file to work on a windows and mac system also.. i tried to do it using "platforms field" in pex_binary target but it did not work as expected. '''
Copy code
pex_binary(
    name="app_linux",
    entry_point="app.py",
    dependencies=[
        ":auth_package",
    ],
    output_path="auth/app_linux.pex",
    platforms=["linux-x86_64-cp-311-cp311"],
    interpreter_constraints=["CPython==3.11.5"],
)
same pex_binary for "windows-x86_64-cp-311-cp311"
windows one does not get created only and the linux one gets created but says you need 3.9 to run pex file...
e
Pex does not yet work on Windows (except under WSL); so for that case you simply can't do that yet. For the
pex_binary
targeting Linux, if you build the Pex on Linux with CPython 3.11.5 present, there is generally no need to specify
platforms
at all. If not, say you're on Mac building a PEX for Linux or on Linux building a PEX for Mac; then use
complete_platforms
instead of
platforms
and generate a complete platform JSON platform descriptor on the machine you wish to run the PEX on as described here: https://www.pantsbuild.org/docs/reference-pex_binary#codecomplete_platformscode
q
okay will try it soon