perfetto icon indicating copy to clipboard operation
perfetto copied to clipboard

TraceProcessor library not working on exe made with pyinstaller

Open sagargaddam opened this issue 3 years ago • 4 comments

[I am using TraceProcessor library for making a systrace analysis tool. The tool is working fine when running from IDE. I am trying to create an exe of the tool with pyinstaller but the library is not working with the exe. After some debugging found the following root cause of the issue.

The shell.py (https://github.com/google/perfetto/blob/master/python/perfetto/trace_processor/shell.py)) of the library is using sys.executable to get the path of the python interpreter in case of windows machine. shell_path = platform_delegate.get_shell_path(bin_path=bin_path) if os.name == 'nt' and not shell_path.endswith('.exe'): tp_exec = [sys.executable, shell_path] else: tp_exec = [shell_path]

It later uses this path to connect to trace_processor_python_api.

Now the main problem is, in the exe generated with pyinstaller, the sys.executable returns the path of the generated exe (https://pyinstaller.org/en/stable/runtime-information.html) instead of python interpreter which is causing the library to break.

Please help if anyone have any idea on how to solve this.

sagargaddam avatar Jun 11 '23 07:06 sagargaddam

This a real issue, but it's not high priority for us. Feel free to send patches (https://perfetto.dev/docs/contributing/getting-started) if you find the solution.

aMayzner avatar Jun 12 '23 14:06 aMayzner

This issue is caused by python interpreter path not found after the project was packaged as an exe. A possible solution is to dynamically acquire the python interpreter path:

  # get Python interpreter path
  if not getattr(sys, 'frozen', False):
    python_executable_path = sys.executable
  else:
    python_executable_path = shutil.which('python')

  if os.name == 'nt' and not shell_path.endswith('.exe'):
    tp_exec = [python_executable_path, shell_path]
  else:
    tp_exec = [shell_path]

AnnAVilloV avatar May 07 '25 06:05 AnnAVilloV

Feel free to send a pull request for this.

LalitMaganti avatar May 07 '25 14:05 LalitMaganti

Thanks, AnnAVilloV.

It works for me.

stmazoni avatar Jun 02 '25 04:06 stmazoni