rbonghi / jetson_stats

📊 Simple package for monitoring and control your NVIDIA Jetson [Orin, Xavier, Nano, TX] series
https://rnext.it/jetson_stats
GNU Affero General Public License v3.0
2.14k stars 261 forks source link

Crash when running python executable with pyinstaller #145

Closed peza8 closed 1 year ago

peza8 commented 3 years ago

Summary

I had an issue trying to create a python executable of a program that uses jetson-stats (jtop). Using pyinstaller it's possible to create the executable/bin file without any errors, but when running the program, there's a FileNotFounfError: [Errno 2] ...

The issue comes from this method:

# In jtop/core/common.py

def get_var(MATCH_RE):
    """
    Show the version of this package

    :return: Version number
    :rtype: string
    """
    # Load version package
    Currently breaks compilation to py executable
    with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../', "__init__.py")) as fp:
        match = MATCH_RE.match(fp.read())
        value = match.group(1) if match else ''.join(choice(ascii_letters) for i in range(16))
    return value

    # Issue line is:
    # with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../', "__init__.py")) as fp

The issue, to my eye, is that the use of the absolute path breaks when running the executable. I would have tried to open a PR to fix this, but I wasn't sure how to test this. (As an asside, this method doesn't do what the docstring says, it returns the authors name). In testing I simply hard coded a string to return and it was all good.

Related question: Is the requirement for the link to service going to be an issue if trying to distribute an executable? I imagine the target jetson will have to have the service running.

To Reproduce

  1. Create a basic project with a main.py file and pip install jetson-stats
  2. Use jtop in the main file:
from jtop import jtop

def main():
     jetson = jtop()

if __name__ == "__main__":
    main()
  1. Create an executable using pyinstaller: $ pyinstaller main.py
  2. Run the executable in the dist folder: $ ./dist/main/main

Expected behavior

Nominal program start

Additional info

Board

Jetson-Stats

rbonghi commented 1 year ago

Hi @peza8 ,

I know I reply really late! I never used pyinstaller, but I think you cannot make a "packaged app without installing a Python interpreter". When jetson_stats is installed, add a new ubuntu service and other files to be able to read the hardware configuration.

I temporary close this issue, but feel free to reopen if I misunderstood