2020-06-25 12:38:12 -07:00
.. _building-ray:
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
Building Ray from Source
=========================
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
For majority of Ray users, installing Ray via the latest wheels or pip package is usually enough. However, you may want to build the latest master branch.
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
.. tip :: If you are only editing Python files, follow instructions for :ref: `python-develop` to avoid long build times.
2020-06-18 14:12:12 -07:00
2020-06-25 12:38:12 -07:00
.. contents ::
:local:
2020-06-18 14:12:12 -07:00
2020-03-22 16:42:20 -07:00
.. _python-develop:
2020-06-25 12:38:12 -07:00
Building Ray (Python Only)
--------------------------
2020-03-22 16:42:20 -07:00
.. note :: Unless otherwise stated, directory and file paths are relative to the project root directory.
2020-06-25 12:38:12 -07:00
RLlib, Tune, Autoscaler, and most Python files do not require you to build and compile Ray. Follow these instructions to develop Ray's Python files locally without building Ray.
2020-03-22 16:42:20 -07:00
1. Pip install the **latest Ray wheels.** See :ref: `install-nightlies` for instructions.
2020-06-25 12:38:12 -07:00
.. code-block :: shell
pip install -U https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-0.9.0.dev0-cp38-cp38-manylinux1_x86_64.whl
2020-03-22 16:42:20 -07:00
2. Fork and clone the project to your machine. Connect your repository to the upstream (main project) ray repository.
.. code-block :: shell
git clone https://github.com/[your username]/ray.git
cd ray
git remote add upstream https://github.com/ray-project/ray.git
# Make sure you are up-to-date on master.
2020-06-27 21:28:11 +02:00
3. Replace Python files in the installed package with your local editable copy. We provide a simple script to help you do this: `` python python/ray/setup-dev.py `` .
Running the script will remove the `` ray/tune `` , `` ray/rllib `` , `` ray/autoscaler `` dir (among other directories) bundled with the `` ray `` pip package, and replace them with links to your local code. This way, changing files in your git clone will directly affect the behavior of your installed ray.
.. warning :: Do not run `` pip uninstall ray `` or `` pip install -U `` (for Ray or Ray wheels) if setting up your environment this way. To uninstall or upgrade, you must first `` rm -rf `` the pip-installation site (usually a `` site-packages/ray `` location), then do a pip reinstall (see 1. above), and finally run the above `setup-dev.py` script again.
2020-03-04 13:13:21 -08:00
2020-06-25 12:38:12 -07:00
.. code-block :: shell
2020-03-04 13:13:21 -08:00
2020-06-25 12:38:12 -07:00
cd ray
python python/ray/setup-dev.py
# This replaces miniconda3/lib/python3.7/site-packages/ray/tune
# with your local `ray/python/ray/tune` .
2020-03-04 13:13:21 -08:00
2020-06-25 12:38:12 -07:00
Building Ray (full)
-------------------
2019-02-14 13:50:21 -08:00
2020-06-25 12:38:12 -07:00
.. tip :: If you are only editing Tune/RLlib/Autoscaler files, follow instructions for :ref: `python-develop` to avoid long build times.
2019-02-14 13:50:21 -08:00
2020-06-25 12:38:12 -07:00
To build Ray, first install the following dependencies.
2019-02-14 13:50:21 -08:00
2020-06-25 12:38:12 -07:00
For Ubuntu, run the following commands:
2019-02-14 13:50:21 -08:00
.. code-block :: bash
2020-06-25 12:38:12 -07:00
sudo apt-get update
sudo apt-get install -y build-essential curl unzip psmisc
2019-05-26 11:27:53 -07:00
2020-06-25 12:38:12 -07:00
pip install cython==0.29.0 pytest
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
For MacOS, run the following commands:
2018-06-05 20:22:11 -07:00
2020-06-25 12:38:12 -07:00
.. code-block :: bash
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
brew update
brew install wget
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
pip install cython==0.29.0 pytest
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
For Windows, see the :ref: `Windows Dependencies <windows-dependencies>` section.
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
Ray can be built from the repository as follows.
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
.. code-block :: bash
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
git clone https://github.com/ray-project/ray.git
2018-01-19 16:16:45 -08:00
2020-06-25 12:38:12 -07:00
# Install Bazel.
2020-07-21 13:35:29 -07:00
# (Windows users: please manually place Bazel in your PATH, and point BAZEL_SH to MSYS2's Bash.)
2020-06-25 12:38:12 -07:00
ray/ci/travis/install-bazel.sh
2019-01-26 00:15:48 -08:00
2020-06-25 12:38:12 -07:00
# Optionally build the dashboard
# (requires Node.js, see https://nodejs.org/ for more information).
pushd ray/python/ray/dashboard/client
npm ci
npm run build
popd
2019-01-26 00:15:48 -08:00
2020-06-25 12:38:12 -07:00
# Install Ray.
cd ray/python
pip install -e . --verbose # Add --user if you see a permission denied error.
2019-01-26 00:15:48 -08:00
2020-06-25 12:38:12 -07:00
The `` -e `` means "editable", so changes you make to files in the Ray
directory will take effect without reinstalling the package.
2019-01-26 00:15:48 -08:00
2020-06-25 12:38:12 -07:00
.. warning :: if you run `` python setup.py install `` , files will be copied from the Ray directory to a directory of Python packages (`` /lib/python3.6/site-packages/ray `` ). This means that changes you make to files in the Ray directory will not have any effect.
2019-12-18 16:20:05 -08:00
2020-02-04 14:07:51 -08:00
2020-06-25 12:38:12 -07:00
Fast, Debug, and Optimized Builds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-02-04 14:07:51 -08:00
2020-06-25 12:38:12 -07:00
Currently, Ray is built with optimizations, which can take a long time and
interfere with debugging. To perform fast, debug, or optimized builds, you can
run the following (via `` -c `` `` fastbuild `` /`` dbg `` /`` opt `` , respectively):
2019-01-26 00:15:48 -08:00
.. code-block :: shell
2020-06-25 12:38:12 -07:00
bazel build -c fastbuild //:ray_pkg
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
This will rebuild Ray with the appropriate options (which may take a while).
If you need to build all targets, you can use `` "//:*" `` instead of
`` //:ray_pkg `` .
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
To make this change permanent, you can add an option such as the following
line to your user-level `` ~/.bazelrc `` file (not to be confused with the
workspace-level `` .bazelrc `` file):
2019-06-06 18:18:24 -07:00
.. code-block :: shell
2020-06-25 12:38:12 -07:00
build --compilation_mode=fastbuild
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
If you do so, remember to revert this change, unless you want it to affect
all of your development in the future.
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
Using `` dbg `` instead of `` fastbuild `` generates more debug information,
which can make it easier to debug with a debugger like `` gdb `` .
2019-12-18 16:20:05 -08:00
2020-02-04 14:07:51 -08:00
Building the Docs
-----------------
2020-03-22 16:42:20 -07:00
If you make changes that require documentation changes, don't forget to
2020-02-04 14:07:51 -08:00
update the documentation!
When you make documentation changes, build them locally to verify they render
correctly. `Sphinx <http://sphinx-doc.org/> `_ is used to generate the documentation.
.. code-block :: shell
2020-06-25 12:38:12 -07:00
cd doc
pip install -r requirements-doc.txt
2020-09-01 14:17:20 -07:00
pip install -U -r requirements-rtd.txt # important for reproducing the deployment environment
2020-06-25 12:38:12 -07:00
make html
2020-02-04 14:07:51 -08:00
2020-03-22 16:42:20 -07:00
Once done, the docs will be in `` doc/_build/html `` . For example, on Mac
OSX, you can open the docs (assuming you are still in the `` doc ``
2020-02-04 14:07:51 -08:00
directory) using `` open _build/html/index.html `` .
2020-03-22 16:42:20 -07:00
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
Using a local repository for dependencies
-----------------------------------------
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
If you'd like to build Ray with custom dependencies (for example, with a
different version of Cython), you can modify your `` .bzl `` file as follows:
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
.. code-block :: python
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
http_archive(
name = "cython",
...,
) if False else native.new_local_repository(
name = "cython",
build_file = "bazel/BUILD.cython",
path = "../cython",
)
2019-12-18 16:20:05 -08:00
2020-06-25 12:38:12 -07:00
This replaces the existing `` http_archive `` rule with one that references a
sibling of your Ray directory (named `` cython `` ) using the build file
provided in the Ray repository (`` bazel/BUILD.cython `` ).
If the dependency already has a Bazel build file in it, you can use
`` native.local_repository `` instead, and omit `` build_file `` .
2019-01-26 00:15:48 -08:00
2020-06-25 12:38:12 -07:00
To test switching back to the original rule, change `` False `` to `` True `` .
2019-01-26 00:15:48 -08:00
2020-02-04 14:07:51 -08:00
.. _`PR template`: https://github.com/ray-project/ray/blob/master/.github/PULL_REQUEST_TEMPLATE.md