<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Ray as a cluster library instead of notebook-scoped library in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/ray-as-a-cluster-library-instead-of-notebook-scoped-library/m-p/7932#M3668</link>
    <description>&lt;P&gt;&lt;A href="https://docs.databricks.com/machine-learning/ray-integration.html" alt="https://docs.databricks.com/machine-learning/ray-integration.html" target="_blank"&gt;This article&lt;/A&gt; rightly suggests to install `ray` with `%pip`, although it fails to mention that installing it as a cluster library won't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason, I think, is that `setup_ray_cluster` will use `sys.executable` (ie `/local_disk0/.ephemeral_nfs/envs/pythonEnv-{UUID}/bin/python`) to run &lt;A href="https://github.com/ray-project/ray/blob/master/python/ray/util/spark/start_ray_node.py" alt="https://github.com/ray-project/ray/blob/master/python/ray/util/spark/start_ray_node.py" target="_blank"&gt;start_ray_node.py&lt;/A&gt;, which in turn calls the `ray` executable command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If `ray` is installed with `%pip` its executable command will be in the same folder as `sys.executable` and so everything works fine, but if `ray` is installed as a cluster library (ie in `/local_disk0/.ephemeral_nfs/cluster_libraries/python`) then it won't find it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've tried to add it to PATH but didn't work&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import sys
&amp;nbsp;
sys.path.append("/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And some more debugging (in a new session)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import subprocess
import sys
import os
&amp;nbsp;
print("/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin" in sys.path)  # False
print("/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin" in os.environ["PATH"])  # True
print(subprocess.run(["ray", "--version"], capture_output=True).stdout.decode("utf-8"))  # ray, version 2.3.0
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 20:39:45 GMT</pubDate>
    <dc:creator>Fed</dc:creator>
    <dc:date>2023-03-10T20:39:45Z</dc:date>
    <item>
      <title>Ray as a cluster library instead of notebook-scoped library</title>
      <link>https://community.databricks.com/t5/data-engineering/ray-as-a-cluster-library-instead-of-notebook-scoped-library/m-p/7932#M3668</link>
      <description>&lt;P&gt;&lt;A href="https://docs.databricks.com/machine-learning/ray-integration.html" alt="https://docs.databricks.com/machine-learning/ray-integration.html" target="_blank"&gt;This article&lt;/A&gt; rightly suggests to install `ray` with `%pip`, although it fails to mention that installing it as a cluster library won't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason, I think, is that `setup_ray_cluster` will use `sys.executable` (ie `/local_disk0/.ephemeral_nfs/envs/pythonEnv-{UUID}/bin/python`) to run &lt;A href="https://github.com/ray-project/ray/blob/master/python/ray/util/spark/start_ray_node.py" alt="https://github.com/ray-project/ray/blob/master/python/ray/util/spark/start_ray_node.py" target="_blank"&gt;start_ray_node.py&lt;/A&gt;, which in turn calls the `ray` executable command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If `ray` is installed with `%pip` its executable command will be in the same folder as `sys.executable` and so everything works fine, but if `ray` is installed as a cluster library (ie in `/local_disk0/.ephemeral_nfs/cluster_libraries/python`) then it won't find it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've tried to add it to PATH but didn't work&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import sys
&amp;nbsp;
sys.path.append("/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And some more debugging (in a new session)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import subprocess
import sys
import os
&amp;nbsp;
print("/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin" in sys.path)  # False
print("/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin" in os.environ["PATH"])  # True
print(subprocess.run(["ray", "--version"], capture_output=True).stdout.decode("utf-8"))  # ray, version 2.3.0
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 20:39:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/ray-as-a-cluster-library-instead-of-notebook-scoped-library/m-p/7932#M3668</guid>
      <dc:creator>Fed</dc:creator>
      <dc:date>2023-03-10T20:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Ray as a cluster library instead of notebook-scoped library</title>
      <link>https://community.databricks.com/t5/data-engineering/ray-as-a-cluster-library-instead-of-notebook-scoped-library/m-p/7933#M3669</link>
      <description>&lt;P&gt;Ugly, but this seems to work for now&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import sys
import os
import shutil
from ray.util.spark import setup_ray_cluster, shutdown_ray_cluster
&amp;nbsp;
shutil.copy(
    "/local_disk0/.ephemeral_nfs/cluster_libraries/python/bin/ray",
    os.path.dirname(sys.executable),
)
&amp;nbsp;
setup_ray_cluster(
  num_worker_nodes=4,
  num_cpus_per_node=8,
  collect_log_to_path="/dbfs/ray/logs"
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 21:03:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/ray-as-a-cluster-library-instead-of-notebook-scoped-library/m-p/7933#M3669</guid>
      <dc:creator>Fed</dc:creator>
      <dc:date>2023-03-10T21:03:14Z</dc:date>
    </item>
  </channel>
</rss>

