0

Using the pex tool to package python proyects (https://pex.readthedocs.io/en/v2.1.55/); is there a way to know where the original Pex file is located?. Until now I just have been able to see where the "unzipped" files are located but need to programmatically resolve the original file location since the program can run under different environments. I have a test script ~/print_location.py

import pathlib

print(pathlib.Path(__file__))

And the pex binary ~/print_location.pex

Output:/home/usr/.pex/installed_wheels/4d...e5/print_location-1-py3-none-any.whl/print_location.py

Expected:/home/usr/print_location.pex

Alexis
  • 23
  • 1
  • 4

2 Answers2

1

As of Pex 2.1.53 (https://github.com/pantsbuild/pex/blob/main/CHANGES.rst#2153) at runtime a PEX exposes the original PEX file location in the "PEX" environment variable.

John Sirois
  • 351
  • 1
  • 4
0

sys.argv[0] should be able to get you what you want.

documentation

bwang
  • 96
  • 1
  • 2