TraceProcessor library not working on exe made with pyinstaller
[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.
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.
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]
Feel free to send a pull request for this.