admin管理员组

文章数量:1399329

Consider this script /tmp/test.py:

import os
import sys
print(__file__)
print(os.path.dirname(os.path.realpath(__file__)))
print(sys.argv)

bundled like this with pex:

python -m pex --exe test.py -o test.pex

Executing ./test.pex gives:

/home/user/.cache/pex/unzipped_pexes/1/05ee97ddfe7a3cfe9392492e49c46d07135e26d9/__pex_executable__.py
/home/user/.cache/pex/user_code/0/242a6d4429f13194d3dedebc8dbd8d72bf0c79bd
['/home/user/.cache/pex/unzipped_pexes/1/05ee97ddfe7a3cfe9392492e49c46d07135e26d9/__pex_executable__.py']

How can I get the name and path of the executed .pex file?

Consider this script /tmp/test.py:

import os
import sys
print(__file__)
print(os.path.dirname(os.path.realpath(__file__)))
print(sys.argv)

bundled like this with pex:

python -m pex --exe test.py -o test.pex

Executing ./test.pex gives:

/home/user/.cache/pex/unzipped_pexes/1/05ee97ddfe7a3cfe9392492e49c46d07135e26d9/__pex_executable__.py
/home/user/.cache/pex/user_code/0/242a6d4429f13194d3dedebc8dbd8d72bf0c79bd
['/home/user/.cache/pex/unzipped_pexes/1/05ee97ddfe7a3cfe9392492e49c46d07135e26d9/__pex_executable__.py']

How can I get the name and path of the executed .pex file?

Share Improve this question asked Mar 25 at 8:08 spinkusspinkus 8,5704 gold badges44 silver badges72 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

PEX applications expose a PEX environment variable that is the absolute path of the PEX file.

print(os.environ["PEX"])

本文标签: pythonGet name of executed pex fileStack Overflow