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

billowy-kite-9901

05/31/2022, 11:41 AM
Hi everyone! I am trying to package a Python application used for manufacturing HW devices into a PEX file. One module of the app calls a makefile that in turn calls some small Python scripts. The problem is that these scripts require Python packages, that are available in the PEX environment, but it appears that they are not on python include path when
/usr/bin/env python
is called from the makefile. Is there a way to give the same PEX environment ("installed" packages) to python scripts called this way? 🤔
e

enough-analyst-54434

05/31/2022, 11:51 AM
Have you tried setting
execution_mode="venv"
on the relevant
pex_binary
target(s)?: https://www.pantsbuild.org/docs/reference-pex_binary#codeexecution_modecode
That installs the PEX as a venv and prepends the venv
bin/
dir to the
PATH
.
b

billowy-kite-9901

05/31/2022, 11:57 AM
I just tried passing
--venv
to the
pex
tool and running the resulting file with
PEX_VENV=1 ./my-pex-file.pex
, but
python
still resolves to
/usr/bin/python
e

enough-analyst-54434

05/31/2022, 12:01 PM
You'll need to pass
--venv prepend
if manually using Pex (Pants does this for you).
And you don't need
PEX_VENV=1
when running that PEX,
--venv ...
bakes the execution mode into the PEX's metadata.
b

billowy-kite-9901

05/31/2022, 12:04 PM
whoa, this did the trick!
I couldn't find much info about the
--venv
option on the readthedocs site: https://pex.readthedocs.io/en/latest/buildingpex.html
I am not (yet?) using pants, found out about the PEX format recently and thought - it will be great to distribute this weird app as a single-file
e

enough-analyst-54434

05/31/2022, 12:07 PM
pex --help
says more.
Yeah, I need to make time to freshen the doc site. In the meantime
pex --help
and
pex --help-variables
are your best bets.
👍 1
You may like
--sh-boot
.