Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pex packaging a simple script file

I created a simple python script file called main.py which requires some dependency libraries. I pip installed freezed them into a requirements.txt (in a virtualenv) and now I want to package them both to make a single executable that just runs the script

what's the right way to generate it?

thanks in advance

like image 491
akiva Avatar asked Oct 26 '25 09:10

akiva


1 Answers

To generate a out.pex file from your main.py script and requirements.txt file, you can utilize the following command:

pex -r requirements.txt --exe main.py -o out.pex

It's important to note that the resulting pex file will include your code and its dependencies, but it will not include the Python interpreter. Hence, it is necessary to ensure that the target machine has the appropriate Python interpreter installed.

When you generate the out.pex file using pex 2.1.137, the resulting file structure will typically resemble the following:

.bootstrap/
.deps/  <-- Dependencies will be stored in this directory.
__pex__/
__main__.py  <-- This is the actual entry-point that uses a shebang (hash sign) and wraps your main.py script.
__pex_executable__.py  <-- Your main.py script will be located here.
PEX-INFO
like image 99
Alireza Roshanzamir Avatar answered Oct 28 '25 23:10

Alireza Roshanzamir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!