ray-project / ray

Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
https://ray.io
Apache License 2.0
33.02k stars 5.59k forks source link

Ray with PyInstaller #27421

Open frknayk opened 2 years ago

frknayk commented 2 years ago

What happened + What you expected to happen

Ray cannot work with the python executable (installed with PyInstaller package).

I created a conda environment with numpy,pandas and ray library for PyQt-GUI based application. Ray is installed via pip install -U ray to the conda environment and then ray library is added to PyInstaller installation with --hidden-import command.

Here is the error I'm facing, ray.get([parallel_function.remote( File "ray\remote_function.py", line 111, in _remote_proxy File "ray\util\tracing\tracing_helper.py", line 303, in _invocation_remote_span File "ray\remote_function.py", line 177, in _remote File "ray_private\client_mode_hook.py", line 124, in client_mode_should_convert File "ray_private\client_mode_hook.py", line 105, in wrapper File "ray\worker.py", line 1039, in init File "ray\node.py", line 269, in init File "ray\node.py", line 1080, in start_head_processes File "ray\node.py", line 920, in start_gcs_server File "ray_private\services.py", line 1540, in start_gcs_server File "ray_private\services.py", line 775, in start_ray_process File "ray_private\services.py", line 175, in init File "subprocess.py", line 858, in init File "subprocess.py", line 1311, in _execute_child FileNotFoundError: [WinError 2] The system cannot find the file specified

Is it possible or not to use the ray library in a python executable?

Versions / Dependencies

Ray's Version: 1.13.0

Reproduction script

Create conda environment with ray,pandas,numpy and pyqt. Create executable with PyInstaller and try to see if ray is able to work or not

Issue Severity

No response

richardliaw commented 2 years ago

@mattip is this something you can look into?

mattip commented 2 years ago

ray may need a hook for pyinstaller. Could you provide a more complete reproducer in the form of commands to create the conda environment, a demo application, and the command line you are using to create the pyinstaller package?

There are other open issues about pyinstaller: #16338, #14993, #15396. It would be nice to have a minimum viable reproducer that then we can make work. I imagine using PyInstaller with a Py-QT GUI is not that uncommon.

mattip commented 1 year ago

Still waiting for a reproducer script ...

cberri commented 1 year ago

I have exactly the same issue. Should I provide anything to help with this? I am really looking forward to have Ray integrated on our Windows 10 app.

mattip commented 1 year ago

@cberri we need a complete minimal reproducer that fails. It should include ray and PyQT and a pyinstaller script to bind them into an exe.

cberri commented 1 year ago

Thank you @mattip for your quick replay. Really appreciated. I think we can come up with what you suggested in the next few days and share it with you. I also found an interesting discussion on pyinstaller github issue (pyinstaller and ray: https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/104). I am not sure if you are already aware of that but maybe gives some starting ideas.

cberri commented 1 year ago

@mattip, we have put together a minimal reproducer that fails:

Here is the error after building the .exe with pyinstalller and running the minimal GUI with ray:

Traceback (most recent call last):
  File "test_GUI.py", line 29, in get_ray_features
  File "test_feature_extract.py", line 27, in get_features
  File "ray\_private\client_mode_hook.py", line 105, in wrapper
  File "ray\_private\worker.py", line 1420, in init
  File "ray\_private\node.py", line 271, in __init__
  File "ray\_private\node.py", line 1053, in start_head_processes
  File "ray\_private\node.py", line 899, in start_gcs_server
  File "ray\_private\services.py", line 1417, in start_gcs_server
  File "ray\_private\services.py", line 815, in start_ray_process
  File "ray\_private\services.py", line 172, in __init__
  File "subprocess.py", line 858, in __init__
  File "subprocess.py", line 1311, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

Steps to run the basic tool on Windows 10 in a conda environment named pyrayqt:

  1. Create the conda environment with the following dependencies:

    # To manually install the yml run: conda env create -f environment_Win10.yml
    # setproctitle and psutil are needed for pyinstaller build
    name: pyrayqt
    channels:
       - conda-forge
    dependencies:
       - pip
       - python=3.8
       - pyqt=5.15.7
       - pyqtwebengine=5.15.7
       - pyinstaller
       - pip:
           - ray==2.0.0
           - setproctitle
           - psutil
           - rais

    I saved the file as environment_Win10.yml and created the env by running: conda env create -f environment_Win10.yml

  2. We created two .py files test_GUI.py to run the GUI and test_feature_extract.py for ray

    test_GUI.py

    import sys
    from PyQt5 import QtCore, QtWidgets
    from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
    from PyQt5.QtWidgets import QPushButton
    from PyQt5.QtCore import QSize    
    import test_feature_extract as tfe
    import time
    
    # pyinstaller test_GUI.py --hidden-import=msgpack --noconfirm --clean
    
    class MainWindow(QMainWindow):
       def __init__(self):
           QMainWindow.__init__(self)
    
           self.setMinimumSize(QSize(400, 200))
           self.setMaximumSize(QSize(400, 200))
           self.setWindowTitle("PyRayQt Minimal")
    
           button = QPushButton('Click Here', self)
           button.clicked.connect(self.get_ray_features)
           button.resize(100, 50)
           button.move(150, 80)
           self.label = QLabel('Output:', self)
           self.label.move(150, 20)
    
       def get_ray_features(self):
           print('Clicked.')
           features = tfe.get_features() 
           self.label.setText(''.join(str(e) for e in features))
           print('Finished')
    
    app = QtWidgets.QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit( app.exec_() )

    test_feature_extract.py

    import ray
    import time
    import json
    
    @ray.remote
    def f(i):
       time.sleep(2)
       return i
    
    def get_features():
    
       # Copy ray from conda env to pyinstaller >> dist >> application name solve the error
       # However a different error occurs with log dashboard in ray_tmp. include_dashboard=False crashed the terminal
       '''
       ray.init(ignore_reinit_error=True, num_cpus=2, include_dashboard=False,
           _temp_dir="PATH_TO_SPILL\\ray_tmp\\ray",
           _system_config={
               "object_spilling_config": json.dumps(
                   {"type": "filesystem", "params": {"directory_path": "PATH_TO_SPILL\\ray_tmp\\spill"}},
               )
           },
           address='local'
       )
       '''
    
       ray.init(ignore_reinit_error=True, num_cpus=2)
       features = [f.remote(i) for i in range(10)]
       get_features = ray.get(features)
       ray.shutdown()
    
       return get_features
  3. We built the .exe after activating the pyrayqt env as follows:

    pyinstaller test_GUI.py --hidden-import=msgpack --noconfirm --clean

    In case you prefer the pyinstaller .spec file you can use the following after saving the spec file as test_GUI.spec to build the .exe

    # -*- mode: python ; coding: utf-8 -*-
    
    block_cipher = None
    
    a = Analysis(
       ['test_GUI.py'],
       pathex=[],
       binaries=[],
       datas=[],
       hiddenimports=['msgpack'],
       hookspath=[],
       hooksconfig={},
       runtime_hooks=[],
       excludes=[],
       win_no_prefer_redirects=False,
       win_private_assemblies=False,
       cipher=block_cipher,
       noarchive=False,
    )
    pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
    
    exe = EXE(
       pyz,
       a.scripts,
       [],
       exclude_binaries=True,
       name='test_GUI',
       debug=False,
       bootloader_ignore_signals=False,
       strip=False,
       upx=True,
       console=True,
       disable_windowed_traceback=False,
       argv_emulation=False,
       target_arch=None,
       codesign_identity=None,
       entitlements_file=None,
    )
    coll = COLLECT(
       exe,
       a.binaries,
       a.zipfiles,
       a.datas,
       strip=False,
       upx=True,
       upx_exclude=[],
       name='test_GUI',
    )

    To build from .spec you can do the following from the conda env pyinstaller test_GUI.spec

Please let me know if you have any questions or if I should provide you anything else to look into the issue.

Thank you for your help.

mattip commented 1 year ago

Thanks for the reproducer. Do you know if this is windows-specific?

cberri commented 1 year ago

I am not sure about Linux and Mac. I can give a try with the reproducer on Mac and let you know.

mattip commented 1 year ago

What do you do after pyinstaller test_GUI.py --hidden-import=msgpack --noconfirm --clean?

mattip commented 1 year ago

On linux I get

$ ./dist/test_GUI/test_GUI 
Traceback (most recent call last):
  File "test_GUI.py", line 6, in <module>
    import test_feature_extract as tfe
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "test_feature_extract.py", line 1, in <module>
    import ray
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "ray/__init__.py", line 116, in <module>
  File "python/ray/_raylet.pyx", line 117, in init ray._raylet
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "ray/exceptions.py", line 5, in <module>
ModuleNotFoundError: No module named 'colorama'
[658111] Failed to execute script 'test_GUI' due to unhandled exception!
cberri commented 1 year ago

After pyinstaller test_GUI.py --hidden-import=msgpack --noconfirm --clean In Windows 10 I lunch the .exe file from the dist directory created by pyinstaller.

Without --hidden-import=msgpack I get an error when I start the built application. The msgpack is not found. And about --noconfirm --clean to just overwrite an previous build if already there.

For Linux I would maybe try the following:

# If not installed
pip install colorama

and/or

pyinstaller test_GUI.py --hidden-import=msgpack --hidden-import=colorama --noconfirm --clean
mattip commented 1 year ago

Progress. I think the problem was that colorama did not appear in pyrayqt.yml. Now I get

$ ./dist/test_GUI/test_GUI 
Clicked.
Traceback (most recent call last):
  File "test_GUI.py", line 29, in get_ray_features
    features = tfe.get_features() 
  File "test_feature_extract.py", line 28, in get_features
    ray.init(ignore_reinit_error=True, num_cpus=2)
  File "ray/_private/client_mode_hook.py", line 105, in wrapper
  File "ray/_private/worker.py", line 1429, in init
  File "ray/_private/node.py", line 271, in __init__
  File "ray/_private/node.py", line 1058, in start_head_processes
  File "ray/_private/node.py", line 904, in start_gcs_server
  File "ray/_private/services.py", line 1457, in start_gcs_server
  File "ray/_private/services.py", line 815, in start_ray_process
  File "subprocess.py", line 858, in __init__
  File "subprocess.py", line 1704, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/issue27421/dist/test_GUI/ray/core/src/ray/gcs/gcs_server'

This seems to be very close to the original error report. The problem is that ray uses at least one compiled executable gcs_server.exe (on linux gcs_server). I don't see that this is being packaged by pyinstaller. This may not be the only one: there is also raylet.exe and default_worker.exe.

mattip commented 1 year ago

For those following along, I modified the conda yml file to not use rais, and to use the conda-built ray:

# To manually install the yml run: conda env create -f environment_Win10.yml
# setproctitle and psutil are needed for pyinstaller build
name: pyrayqt
channels:
    - conda-forge
dependencies:
    - pip
    - python=3.8
    - pyqt=5.15.7
    - pyqtwebengine=5.15.7
    - pyinstaller
    - ray-core=2.1.0
    - psutil
    - colorama
    - pyinstaller
cberri commented 1 year ago

Thank you for updating the yml file. Interesting that in Windows 10 the colorama dependency was not necessary.

What we have also tried so far was to include (copy and paste) the ray conda env folder into the dist application folder. Not very elegant but we wanted to check if this could help. In this case the error was:

Clicked.
2022-11-15 16:25:22,551 ERROR services.py:1363 - Failed to start the dashboard: Failed to start the dashboard
Failed to read dashboard log: [Errno 2] No such file or directory:
*C: ||Users\lag kuner\\Desktop\\ray_ tmp\\ray\lsession
2022-11-15_16-25-00_636335_1328\\logs\\dashboard.log'
re 2022-11-15 16:25:22,552 ERROR services.py:1364 --Failed to start the dashboard
de Failed to read dashboard log: [Errno 2] No such file or directory:
"C: | |Users\ lag_kuner\ \Desktop\\ray_tmp\\rayllsession
#2022-11-15_16-25-00_636335_1328\\logs\\dashboard.10g'
Traceback (most recent call last) :
File
"ray\ private\services.py'
line 1336, in start dashboard
(FatewittoUnet-deshboarno°2; No such file or directory:
*C: | |Users\ lag _kuner\ \Desktop\\ray_tmp\\ray\lsession_2022-11-15
16-25-00_636335_1328\ \logs\\dashboard.log
During handling of the above exception, another exception occurred:
Traceback (most recent call last) :
File "ray\ private\services.py"
line 1347, in start dashboard
raise Exception(err msg + f"InFailed to read dashboard log: (e}")
Exception: Failed to start the dashboard
Failed to read dashboard log: [Errno 2] No such file or directory:
"C: \Users\lag kuner\\Desktop\\ray tmp\\ray\lsession
2022-11-15 16-25-00 636335 1328\\logs\\dashboard.10g
2022-11-15 16:25:22,765 INFO worker.py:1518
Started a local Ray instance.

I included as commented lines in the **test_feature_extract.py** file (see above)

Not sure if it helps.

mattip commented 1 year ago

Does test_get_features.py work without the GUI?

kevalsp commented 1 year ago

@mattip Yes, it works without the GUI.

cberri commented 1 year ago

Any news about this problem? We really need to know if to continue with ray or choose a different way.

mattip commented 1 year ago

I don't think this is windows-specific, I get errors when trying out the script on linux. Perhaps the pyinstaller folks have some clues where the exes and dlls need to be specified so that ray can be packaged by pyinstaller.

mattip commented 1 year ago

I removed the windows part of the issue title.

iumyidol commented 1 year ago

exactly same error here. In my case it's a console based, no gui, failed to run the .exe

initially getting module not found error, then resolved with --hidden-import but end up with the Error2 OP is getting.

File "python__init.py", line 4, in File "ray_private\client_mode_hook.py", line 105, in wrapper File "ray_private\worker.py", line 1451, in init File "ray_private\node.py", line 287, in init File "ray_private\node.py", line 1119, in start_head_processes File "ray_private\node.py", line 929, in start_gcs_server File "ray_private\services.py", line 1305, in start_gcs_server File "ray_private\services.py", line 864, in start_ray_process File "ray_private\services.py", line 227, in init File "subprocess.py", line 966, in init File "subprocess.py", line 1435, in _execute_child FileNotFoundError: [WinError 2] The system cannot find the file specified [32460] Failed to execute script 'init__' due to unhandled exception!

pyinstaller command i used is:=

pyinstaller --noconfirm --onefile --console --name "image-conerter" --hidden-import "msgpack" --hidden-import "psutil" --hidden-import "setproctitle" --hidden-import "ray._private.memory_monitor" "C:/Users/Hugo/Desktop/working file/python/init.py"

carlpe commented 1 year ago

Greetings,

I had the same problem as you, the way to fix it is by using hooks.

So, make a "hooks" folder in your project directory as such: /MyProject/hooks/

In this folder create a file called /MyProject/hooks/hook-ray.py

Add this to hook-ray.py:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules("ray")
datas = collect_data_files("ray", include_py_files=True)

And then compile as such:

python -O -m PyInstaller --log-level=WARN --noupx --hiddenimport=ray --icon=main.ico --uac-admin --additional-hooks-dir=hooks --name myproject main.py

The program now runs from /MyProject/dist/myproject.exe successfully using Ray.

What I have noticed is that once the ray multiprocessing is initialising and the CPUs warm up, there are opened several new instances of myproject.exe ... much in the same manner as if you neglect to add freeze_support to:

if __name__ == "__main__":
    multiprocessing.freeze_support()

My question is how to avoid this from happening ? Is there freeze_support in Ray?

Please checkout my work-around with hooks, and if you do have any info on the multiple instances of the executable, do leave a reply!

Thanks

samyakjain10 commented 1 year ago

Hi @carlpe, I tried the same method as yours for my app but I am unable to resolve the issue.

Traceback (most recent call last):
  File "main.py", line 4, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\__init__.py", line 136, in <module>
    from ray._private.worker import (  # noqa: E402,F401
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\_private\worker.py", line 59, in <module>
    import ray.actor
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\actor.py", line 38, in <module>
    from ray.util.tracing.tracing_helper import (
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\util\tracing\tracing_helper.py", line 28, in <module>
    from ray.runtime_context import get_runtime_context
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\runtime_context.py", line 6, in <module>
    from ray.runtime_env import RuntimeEnv
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\runtime_env\__init__.py", line 1, in <module>
    from ray.runtime_env.runtime_env import RuntimeEnv, RuntimeEnvConfig  # noqa: E402,F401
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\runtime_env\runtime_env.py", line 12, in <module>
    from ray._private.runtime_env.plugin_schema_manager import RuntimeEnvPluginSchemaManager
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "ray\_private\runtime_env\plugin_schema_manager.py", line 2, in <module>
    import jsonschema
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "jsonschema\__init__.py", line 17, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "jsonschema\validators.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "jsonschema_specifications\__init__.py", line 11, in <module>
  File "referencing\_core.py", line 297, in __rmatmul__
  File "jsonschema_specifications\_core.py", line 27, in _schemas
  File "pathlib.py", line 1122, in iterdir
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\sjsam\\AppData\\Local\\Temp\\_MEI139842\\jsonschema_specifications\\schemas'

FYI, line 4 in main.py is import ray

rohantalwadia commented 1 year ago

Greetings,

I had the same problem as you, the way to fix it is by using hooks.

So, make a "hooks" folder in your project directory as such: /MyProject/hooks/

In this folder create a file called /MyProject/hooks/hook-ray.py

Add this to hook-ray.py:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules("ray")
datas = collect_data_files("ray", include_py_files=True)

And then compile as such:

python -O -m PyInstaller --log-level=WARN --noupx --hiddenimport=ray --icon=main.ico --uac-admin --additional-hooks-dir=hooks --name myproject main.py

The program now runs from /MyProject/dist/myproject.exe successfully using Ray.

What I have noticed is that once the ray multiprocessing is initialising and the CPUs warm up, there are opened several new instances of myproject.exe ... much in the same manner as if you neglect to add freeze_support to:

if __name__ == "__main__":
    multiprocessing.freeze_support()

My question is how to avoid this from happening ? Is there freeze_support in Ray?

Please checkout my work-around with hooks, and if you do have any info on the multiple instances of the executable, do leave a reply!

Thanks

Hey, @carlpe @samyakjain10 Thanks for sharing can you explain how you solved the entry-level issue? It shows me this when trying to submit a ray job to a remote node, I think it's because of the bundled executables.

Error: 1
'ray' is not recognized as an internal or external command,
operable program or batch file.

also for reference here is the spec file

from kivy_deps import sdl2, glew
from ray._private.utils import get_runtime_env_info
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(
    ['File.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[
                    'ray',
                    'ray.core.generated_ray_protocol',
                    'ray.core.generated_raylet',
                    'ray._raylet',
                    'ray._private.utils',
                    'ray._private.filesystem',
                    'ray._private.services',
                    'ray._private.client_mode_hook',
                    'ray._private.istio',
                    'ray._private.telemetry.prometheus_exporter',
                    'ray._private.memory_monitor',
                    ],
    hookspath=['hooks'],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='App-Name',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=False,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    uac_admin=True,
    icon=['icon.ico'],
)
coll = COLLECT(
    exe, Tree('PATH\\'),
    a.binaries,
    a.zipfiles,
    a.datas,
    *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
    strip=False,
    upx=False,
    upx_exclude=[],
    name='App-Name',
)
jonathan-conder-sm commented 12 months ago

the multiprocessing issue can be solved setting sys.executable = "path/to/python" in your main script. Although this kinda defeats the purpose of using pyinstaller in the first place...

paulbareilCodotek commented 5 months ago

I have the exact same problem.

Environment:

Ray Version: 2.10.0 Operating System: Windows 10 Python Version: 3.10.13

requirements.txt

ray==3.10.13 psutil==5.9.8 setproctitle==1.3.3

Reproduction scripts

Here is my test code

import sys
print(sys.path)

def print_python_path_configuration():
    #sys.executable = os.path.join(sys.prefix, 'Scripts', 'python.exe')
    #sys.path.append(os.path.join(sys.prefix, 'Lib', 'site-packages'))
    print("Python path configuration:")
    print(f"  PYTHONHOME = '{sys.prefix}'")
    print(f"  PYTHONPATH = {'(not set)' if not sys.path else sys.path}")
    print(f"  program name = '{sys.executable}'")
    print(f"  isolated = {sys.flags.isolated}")
    print(f"  user site = {sys.flags}")
    print(f"  sys._base_executable = '{sys._base_executable}'")
    print(f"  sys.base_prefix = '{sys.base_prefix}'")
    print(f"  sys.base_exec_prefix = '{sys.base_exec_prefix}'")
    print(f"  sys.platlibdir = '{sys.platlibdir}'")
    print(f"  sys.executable = '{sys.executable}'")
    print(f"  sys.prefix = '{sys.prefix}'")
    print(f"  sys.exec_prefix = '{sys.exec_prefix}'")
    print(f"  sys.path = {sys.path}")
    #os.environ["RAY_PYTHON"] = os.path.join(sys.prefix, 'Scripts', 'python.exe')

print('setting paths')
print_python_path_configuration()

import ray
print('ray imported')

print('calling ray.init()')
ray.init()

Here is the pyinstaller spec file

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules("ray")

datas = [
    # required to prevent the rgb.txt missing data
    ('venv\Lib\site-packages\colorful\data', 'colorful/data'),
]

datas += collect_data_files("ray", include_py_files=True)

a = Analysis(
    ['main.py'], pathex=[], binaries=[], datas=datas,
    hiddenimports=hiddenimports, hookspath=['hooks'],
    hooksconfig={}, runtime_hooks=[],
    excludes=[], noarchive=False,)

pyz = PYZ(a.pure)

exe = EXE(
    pyz, a.scripts, [], exclude_binaries=True,
    name='test', debug=False, bootloader_ignore_signals=False,
    strip=False, upx=True,  console=False, disable_windowed_traceback=False,
    argv_emulation=False, target_arch=None, uac_admin=True,
    codesign_identity=None, entitlements_file=None,
)
coll = COLLECT(
    exe, a.binaries, a.datas,
    strip=False, upx=True,
    upx_exclude=[], name='test',
)

With the hook-ray.py inside the hooks folder as

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules("ray")
datas = collect_data_files("ray", include_py_files=True)

Shell ouput

To get more information, I modified my C:\Users\Utilisateur\anaconda3\envs\Py3_10\Lib\subprocess.py file and added the two print outputs below so we see what is the subprocess calls being made.

            print('subprocess:')
            print(args)
            try:
                hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
..... rest of code

It gave me the error below.

C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test>test.exe
subprocess:
C:\Windows\system32\cmd.exe /c "ver"
['C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\base_library.zip', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\lib-dynload', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal']
setting paths
Python path configuration:
  PYTHONHOME = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  PYTHONPATH = ['C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\base_library.zip', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\lib-dynload', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal']
  program name = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe'
  isolated = 1
  user site = sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=1, no_user_site=1, no_site=1, ignore_environment=1, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=1, dev_mode=False, utf8_mode=0, warn_default_encoding=0, int_max_str_digits=-1)
  sys._base_executable = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe'
  sys.base_prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.base_exec_prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.platlibdir = 'lib'
  sys.executable = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe'
  sys.prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.exec_prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.path = ['C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\base_library.zip', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\lib-dynload', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal']
ray imported
calling ray.init()
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\core\src\ray\gcs\gcs_server.exe --log_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --config_list=eyJvYmplY3Rfc3BpbGxpbmdfY29uZmlnIjogIntcInR5cGVcIjogXCJmaWxlc3lzdGVtXCIsIFwicGFyYW1zXCI6IHtcImRpcmVjdG9yeV9wYXRoXCI6IFwiQzpcXFxcVXNlcnNcXFxcVVRJTElTfjFcXFxcQXBwRGF0YVxcXFxMb2NhbFxcXFxUZW1wXFxcXHJheVxcXFxzZXNzaW9uXzIwMjQtMDMtMjJfMDktMzEtMDdfNzM3MDE3XzIyNDQ0XCJ9fSIsICJpc19leHRlcm5hbF9zdG9yYWdlX3R5cGVfZnMiOiB0cnVlfQ== --gcs_server_port=63414 --metrics-agent-port=64239 --node-ip-address=127.0.0.1 --session-name=session_2024-03-22_09-31-07_737017_22444
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\autoscaler\_private\monitor.py --logs-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:63414 --monitor-ip=127.0.0.1
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\dashboard.py --host=127.0.0.1 --port=8265 --port-retries=50 --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --log-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --session-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:63414 --node-ip-address=127.0.0.1
2024-03-22 09:31:37,288 ERROR services.py:1330 -- Failed to start the dashboard
2024-03-22 09:31:37,310 ERROR services.py:1355 -- Error should be written to 'dashboard.log' or 'dashboard.err'. We are printing the last 20 lines for you. See 'https://docs.ray.io/en/master/ray-observability/ray-logging.html#logging-directory-structure' to find where the log file is.
2024-03-22 09:31:37,317 ERROR services.py:1365 -- Couldn't read dashboard.log file. Error: [Errno 2] No such file or directory: 'C:\\Users\\UTILIS~1\\AppData\\Local\\Temp\\ray\\session_2024-03-22_09-31-07_737017_22444\\logs\\dashboard.log'. It means the dashboard is broken even before it initializes the logger (mostly dependency issues). Reading the dashboard.err file which contains stdout/stderr.
2024-03-22 09:31:37,318 ERROR services.py:1399 -- Failed to read dashboard.err file: cannot mmap an empty file. It is unexpected. Please report an issue to Ray github. https://github.com/ray-project/ray/issues
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\core\src\ray\raylet\raylet.exe --raylet_socket_name=tcp://127.0.0.1:63945 --store_socket_name=tcp://127.0.0.1:64900 --object_manager_port=0 --min_worker_port=0 --max_worker_port=0 --node_manager_port=0 --node_ip_address=127.0.0.1 --maximum_startup_concurrency=4 --static_resource_list=node:127.0.0.1,1.0,node:__internal_head__,1.0,CPU,4,memory,2151223296,object_store_memory,1075611648 "--python_worker_command=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\workers\setup_worker.py -S -s C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\workers\default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=RAY_NODE_MANAGER_PORT_PLACEHOLDER --object-store-name=tcp://127.0.0.1:64900 --raylet-name=tcp://127.0.0.1:63945 --redis-address=None --metrics-agent-port=64239 --runtime-env-agent-port=64457 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --runtime-env-agent-port=64457 --gcs-address=127.0.0.1:63414 --session-name=session_2024-03-22_09-31-07_737017_22444 --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --webui=None --cluster-id=be00edda9ffa3881711c9f6d808c4d76f22195e196e0402f3074e714 RAY_WORKER_DYNAMIC_OPTION_PLACEHOLDER" --java_worker_command= --cpp_worker_command= --native_library_path=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\cpp\lib --temp_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --session_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444 --log_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --resource_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\runtime_resources --metrics-agent-port=64239 --metrics_export_port=61632 --runtime_env_agent_port=64457 --object_store_memory=1075611648 --plasma_directory=C:\Users\UTILIS~1\AppData\Local\Temp --ray-debugger-external=0 --gcs-address=127.0.0.1:63414 --session-name=session_2024-03-22_09-31-07_737017_22444 --labels= --cluster-id=be00edda9ffa3881711c9f6d808c4d76f22195e196e0402f3074e714 --head --num_prestart_python_workers=4 "--dashboard_agent_command=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\agent.py --node-ip-address=127.0.0.1 --metrics-export-port=61632 --dashboard-agent-port=64239 --listen-port=52365 --node-manager-port=RAY_NODE_MANAGER_PORT_PLACEHOLDER --object-store-name=tcp://127.0.0.1:64900 --raylet-name=tcp://127.0.0.1:63945 --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --session-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444 --log-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --session-name=session_2024-03-22_09-31-07_737017_22444 --gcs-address=127.0.0.1:63414" "--runtime_env_agent_command=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\runtime_env\agent\main.py --node-ip-address=127.0.0.1 --runtime-env-agent-port=64457 --gcs-address=127.0.0.1:63414 --runtime-env-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\runtime_resources --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --log-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray"
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\log_monitor.py --session-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444 --logs-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-31-07_737017_22444\logs --gcs-address=127.0.0.1:63414 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5
2024-03-22 09:31:39,620 INFO worker.py:1752 -- Started a local Ray instance.

We see that the dashboard command fails to start

C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\dashboard.py -agrsssss!

ERROR services.py:1330 -- Failed to start the dashboard

It is because it tries to run the dashboard.py using the test.exe. In fact, it ends up going into a infinite loop and if I do not stop it, it crashes my PC.

If I change sys.executable to point to python.exe it will work, but ray will faill to connect to workers.

paulbareilCodotek commented 5 months ago

If I modify my path using this code

sys.executable = os.path.join(sys.prefix, 'Scripts', 'python.exe')
os.environ["RAY_PYTHON"] = os.path.join(sys.prefix, 'Scripts', 'python.exe')

and modify datas to add the python.exe in the spec file

datas = [
    # required to prevent the rgb.txt missing data
    ('venv\Lib\site-packages\colorful\data', 'colorful/data'),
    ("venv/Scripts", "Scripts"),
]

I do not have the infinite-loop-taking-all-pc-ressources bug, but it still does not work

C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test>test.exe
subprocess:
C:\Windows\system32\cmd.exe /c "ver"
['C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\base_library.zip', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\lib-dynload', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal']
setting paths
Python path configuration:
  PYTHONHOME = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  PYTHONPATH = ['C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\base_library.zip', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\lib-dynload', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal']
  program name = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe'
  isolated = 1
  user site = sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=1, no_user_site=1, no_site=1, ignore_environment=1, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=1, dev_mode=False, utf8_mode=0, warn_default_encoding=0, int_max_str_digits=-1)
  sys._base_executable = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\test.exe'
  sys.base_prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.base_exec_prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.platlibdir = 'lib'
  sys.executable = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe'
  sys.prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.exec_prefix = 'C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal'
  sys.path = ['C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\base_library.zip', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal\\lib-dynload', 'C:\\Users\\Utilisateur\\PythonProjects\\TestRayPyinstaller\\dist\\test\\_internal']
ray imported
calling ray.init()
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\core\src\ray\gcs\gcs_server.exe --log_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --config_list=eyJvYmplY3Rfc3BpbGxpbmdfY29uZmlnIjogIntcInR5cGVcIjogXCJmaWxlc3lzdGVtXCIsIFwicGFyYW1zXCI6IHtcImRpcmVjdG9yeV9wYXRoXCI6IFwiQzpcXFxcVXNlcnNcXFxcVVRJTElTfjFcXFxcQXBwRGF0YVxcXFxMb2NhbFxcXFxUZW1wXFxcXHJheVxcXFxzZXNzaW9uXzIwMjQtMDMtMjJfMDktNTYtNThfODAzNzI1XzI4ODQwXCJ9fSIsICJpc19leHRlcm5hbF9zdG9yYWdlX3R5cGVfZnMiOiB0cnVlfQ== --gcs_server_port=65296 --metrics-agent-port=64352 --node-ip-address=127.0.0.1 --session-name=session_2024-03-22_09-56-58_803725_28840
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\autoscaler\_private\monitor.py --logs-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:65296 --monitor-ip=127.0.0.1
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\dashboard.py --host=127.0.0.1 --port=8265 --port-retries=50 --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --log-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --session-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:65296 --node-ip-address=127.0.0.1
2024-03-22 09:56:59,828 ERROR services.py:1330 -- Failed to start the dashboard , return code 106
2024-03-22 09:56:59,829 ERROR services.py:1355 -- Error should be written to 'dashboard.log' or 'dashboard.err'. We are printing the last 20 lines for you. See 'https://docs.ray.io/en/master/ray-observability/ray-logging.html#logging-directory-structure' to find where the log file is.
2024-03-22 09:56:59,829 ERROR services.py:1365 -- Couldn't read dashboard.log file. Error: [Errno 2] No such file or directory: 'C:\\Users\\UTILIS~1\\AppData\\Local\\Temp\\ray\\session_2024-03-22_09-56-58_803725_28840\\logs\\dashboard.log'. It means the dashboard is broken even before it initializes the logger (mostly dependency issues). Reading the dashboard.err file which contains stdout/stderr.
2024-03-22 09:56:59,832 ERROR services.py:1399 --
The last 20 lines of C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs\dashboard.err (it contains the error message from the dashboard):
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\core\src\ray\raylet\raylet.exe --raylet_socket_name=tcp://127.0.0.1:64356 --store_socket_name=tcp://127.0.0.1:65488 --object_manager_port=0 --min_worker_port=0 --max_worker_port=0 --node_manager_port=0 --node_ip_address=127.0.0.1 --maximum_startup_concurrency=4 --static_resource_list=node:127.0.0.1,1.0,node:__internal_head__,1.0,CPU,4,memory,8550410651,object_store_memory,4275205324 "--python_worker_command=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\workers\setup_worker.py -S -s C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\workers\default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=RAY_NODE_MANAGER_PORT_PLACEHOLDER --object-store-name=tcp://127.0.0.1:65488 --raylet-name=tcp://127.0.0.1:64356 --redis-address=None --metrics-agent-port=64352 --runtime-env-agent-port=65482 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --runtime-env-agent-port=65482 --gcs-address=127.0.0.1:65296 --session-name=session_2024-03-22_09-56-58_803725_28840 --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --webui=None --cluster-id=22e6a697cb495b2b4be1799fe7c74b85301bdc087cd6cb5b2ae49241 RAY_WORKER_DYNAMIC_OPTION_PLACEHOLDER" --java_worker_command= --cpp_worker_command= --native_library_path=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\cpp\lib --temp_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --session_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840 --log_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --resource_dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\runtime_resources --metrics-agent-port=64352 --metrics_export_port=64151 --runtime_env_agent_port=65482 --object_store_memory=4275205324 --plasma_directory=C:\Users\UTILIS~1\AppData\Local\Temp --ray-debugger-external=0 --gcs-address=127.0.0.1:65296 --session-name=session_2024-03-22_09-56-58_803725_28840 --labels= --cluster-id=22e6a697cb495b2b4be1799fe7c74b85301bdc087cd6cb5b2ae49241 --head --num_prestart_python_workers=4 "--dashboard_agent_command=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\agent.py --node-ip-address=127.0.0.1 --metrics-export-port=64151 --dashboard-agent-port=64352 --listen-port=52365 --node-manager-port=RAY_NODE_MANAGER_PORT_PLACEHOLDER --object-store-name=tcp://127.0.0.1:65488 --raylet-name=tcp://127.0.0.1:64356 --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray --session-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840 --log-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --session-name=session_2024-03-22_09-56-58_803725_28840 --gcs-address=127.0.0.1:65296" "--runtime_env_agent_command=C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\runtime_env\agent\main.py --node-ip-address=127.0.0.1 --runtime-env-agent-port=65482 --gcs-address=127.0.0.1:65296 --runtime-env-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\runtime_resources --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --log-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --temp-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray"
subprocess:
C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\Scripts\python.exe -u C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\log_monitor.py --session-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840 --logs-dir=C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_09-56-58_803725_28840\logs --gcs-address=127.0.0.1:65296 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5
2024-03-22 09:57:00,035 INFO worker.py:1752 -- Started a local Ray instance.
[2024-03-22 09:57:11,158 E 28840 34400] core_worker_process.cc:216: Failed to get the system config from raylet because it is dead. Worker will terminate. Status: GrpcUnavailable: RPC Error message: failed to connect to all addresses; last error: UNAVAILABLE: ipv4:127.0.0.1:63843: Connection refused; RPC Error details:  .Please see `raylet.out` for more details.
paulbareilCodotek commented 5 months ago

If I copy the whole virtual environment to _internals with the Scripts folder and the pyvenv.cfg, or I modify the spec file as below (which is the same). It almost works!

datas = [
    # required to prevent the rgb.txt missing data
    ("venv/Lib/site-packages", "."),
    ("venv/Scripts", "Scripts"),
    ("venv/pyvenv.cfg", "."),  # ending up using the whole venv!
]

The log ends up up 05,866 INFO worker.py:1743 -- Started a local Ray instance. View the dashboard at 127.0.0.1:8265 but it never returns.

If I look at the Dashboard logs, raylet.err gives me

1Traceback (most recent call last):
2  File "C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\_private\workers\default_worker.py", line 7, in <module>
3    import ray
4ModuleNotFoundError: No module named 'ray'

and the dashboard.log says many things the the interesting part seems to be

712024-03-22 10:43:05,603   INFO http_server_head.py:255 -- <ResourceRoute [GET] <DynamicResource  /api/v0/delay/{delay_s}> -> <function StateHead.delayed_response at 0x00000259CD6AC5E0>
722024-03-22 10:43:05,603   INFO http_server_head.py:255 -- <ResourceRoute [GET] <PlainResource  /usage_stats_enabled> -> <function UsageStatsHead.get_usage_stats_enabled at 0x00000259CD6AC940>
732024-03-22 10:43:05,604   INFO http_server_head.py:255 -- <ResourceRoute [GET] <PlainResource  /> -> <function HttpServerDashboardHead.get_index at 0x00000259CD6AD480>
742024-03-22 10:43:05,604   INFO http_server_head.py:255 -- <ResourceRoute [GET] <PlainResource  /favicon.ico> -> <function HttpServerDashboardHead.get_favicon at 0x00000259CD6AD5A0>
752024-03-22 10:43:05,604   INFO http_server_head.py:255 -- <ResourceRoute [GET] <StaticResource  /static -> WindowsPath('C:/Users/Utilisateur/PythonProjects/TestRayPyinstaller/dist/test/_internal/ray/dashboard/client/build/static')> -> <bound method StaticResource._handle of <StaticResource  /static -> WindowsPath('C:/Users/Utilisateur/PythonProjects/TestRayPyinstaller/dist/test/_internal/ray/dashboard/client/build/static')>>
762024-03-22 10:43:05,605   INFO http_server_head.py:256 -- Registered 53 routes.
772024-03-22 10:43:05,605   INFO head.py:332 -- http server initialized at 127.0.0.1:8265
782024-03-22 10:43:05,661   INFO event_utils.py:132 -- Monitor events logs modified after 1711116785.044092 on C:\Users\UTILIS~1\AppData\Local\Temp\ray\session_2024-03-22_10-43-02_629250_7876\logs\events, the source types are all.
792024-03-22 10:43:05,664   INFO usage_stats_head.py:191 -- Usage reporting is disabled.
802024-03-22 10:43:05,666   INFO actor_head.py:101 -- Getting all actor info from GCS.
812024-03-22 10:43:05,676   INFO actor_head.py:123 -- Received 0 actor info from GCS.
822024-03-22 10:43:08,431   INFO state_head.py:422 -- Streaming logs with options: GetLogOptions(timeout=30, node_id='9ac00af9875b6fcf1ecdea4e4d2dcd95eb5cd97bde7fe0890fd7b451', node_ip=None, media_type='file', filename='raylet.err', actor_id=None, task_id=None, attempt_number=0, pid=None, lines=50000, interval=None, suffix='out', submission_id=None)
832024-03-22 10:43:08,432   INFO log_manager.py:444 -- Resolved log file: node_id='9ac00af9875b6fcf1ecdea4e4d2dcd95eb5cd97bde7fe0890fd7b451' filename='raylet.err' start_offset=None end_offset=None
842024-03-22 10:43:08,432   ERROR state_head.py:440 -- Agent for node id: 9ac00af9875b6fcf1ecdea4e4d2dcd95eb5cd97bde7fe0890fd7b451 doesn't exist.
85Traceback (most recent call last):
86  File "C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\modules\state\state_head.py", line 428, in get_logs
87    async for logs_in_bytes in self._log_api.stream_logs(options):
88  File "C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\dashboard\modules\log\log_manager.py", line 113, in stream_logs
89    stream = await self.client.stream_log(
90  File "C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\util\state\state_manager.py", line 92, in api_with_network_error_handler
91    return await func(*args, **kwargs)
92  File "C:\Users\Utilisateur\PythonProjects\TestRayPyinstaller\dist\test\_internal\ray\util\state\state_manager.py", line 466, in stream_log
93    raise ValueError(f"Agent for node id: {node_id} doesn't exist.")
94ValueError: Agent for node id: 9ac00af9875b6fcf1ecdea4e4d2dcd95eb5cd97bde7fe0890fd7b451 doesn't exist.
IrinaOganezova commented 4 months ago

Do you have any progress ?

paulbareilCodotek commented 3 months ago

No, I abandoned Pyinstaller and deployed the whole conda environment instead.