Pyinstaller with ray

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

I am trying to bundle my application using Pyinstaller. Here is what I understand.

When launching the app using Pycharm, at some point the code hits ray.init(). This calls the venv\\lib\\site-packages\\ray\\core\\src\\ray\\gcs\\gcs_server.exe with a bunch of arguments. So in my pyinstaller script I added the first line in the datas list below.

This works well.

datas = [
    ("venv/Lib/site-packages/ray/core/src", "ray/core/src"),
    ("venv/Lib/site-packages/ray/autoscaler", "ray"),
    ("venv/Lib/site-packages/ray/dashboard", "ray/"),
]

Then it calls this code below. So for this I added the second line in the datas list above. However, when running this code with pyinstaller, the sys.executable does not point to python.exe, but to main.exe (i.e. my bundle app) and of course it fails.

venv\Scripts\python.exe -u \venv\lib\site-packages\ray\autoscaler\_private\monitor.py

So the question is how to package ray with pyinstaller? Should I add the monitor.py as another file to build? SHould I bundle the whole python env and catch the -u argument and call the subprocess myself?

Then there will also be the third step involving dashboard.py, but that will be handled similarly to monitor.py

I added a force path sys.executable as shown below to use my existing python environment. I also copy the whole ray folder to the _internal folder of my app.

The ini.ray() goes well, it calls gcs_server.exe, then it calls monitor.py, then dashboard.py, then raylet.exe, then log_monitor.py

Then it hangs after the malformed text shown below.

INFO worker.py:1715 – Started a local Ray instance. View the dashboard at ←[1m←[32m127.0.0.1:8265 ←[39m←[22m

sys.executable = "C:\\Users\\Utilisateur\\PythonProjects\\LRTechREST\\venv\\Scripts\\python.exe"

Usually the rest of my code prints other info, but it just hangs.

I looked at the subprocess calls and they are almost all the same except for the port numbers and a -S -s argument for the non-working version

private\workers\setup_worker.py -S -s default_worker.py
VS
private\workers\setup_worker.py default_worker.py

It hangs when calling this function because print(‘notify_raylet’) is not called.

print('CoreWorker')
worker.core_worker = ray._raylet.CoreWorker(
    mode,
    node.plasma_store_socket_name,
    node.raylet_socket_name,
    job_id,
    gcs_options,
    logs_dir,
    node.node_ip_address,
    node.node_manager_port,
    node.raylet_ip_address,
    (mode == LOCAL_MODE),
    driver_name,
    log_stdout_file_path,
    log_stderr_file_path,
    serialized_job_config,
    node.metrics_agent_port,
    runtime_env_hash,
    startup_token,
    session_name,
    node.cluster_id,
    "" if mode != SCRIPT_MODE else entrypoint,
    worker_launch_time_ms,
    worker_launched_time_ms,
)
print('notify_raylet')