2

Just as reference imagine the following project structure:

/testapp
  | __main__.py
  | firstclass.py
  | secondclass.py

To make installation and deploy easier I decided to bundle these files using the trick below:

  • zip the .py files
  • echo '#!/usr/bin/env python3' | cat - testapp.zip > testapp

The issue now is that "firstclass.py" needs the abspath of "testapp".

If I run this bundled testapp and asks for __file__ it returns the script path, for example the path for "firstclass.py" not "testapp" (the executable).

I also tried using sys.executable, it returns the path for "/usr/bin/python3".

Is there an easy way to get the abspath of "testapp"? I only care for linux environments.

Also the whole point of this is due to the fact that I cannot rely on the name of "testapp", final installer can change that name and I need a reference to it.

Thanks.

tvborda
  • 51
  • 3
  • Similar question? https://stackoverflow.com/questions/12059509/create-a-single-executable-from-a-python-project – C-3PO Nov 10 '22 at 21:08
  • @c-3PO No, definitely not similar. The particular suggested post just describe different ways to pack a python application. The question here is way more specific, thanks anyway. – tvborda Nov 10 '22 at 21:37

0 Answers0