|
1 | | -# Installation |
2 | | -To install and use the ML-Agents Toolkit, follow the steps below. Detailed instructions for each step are provided later on this page. |
| 1 | +# Install the ML-Agents Toolkit |
| 2 | +Set up your system to use the ML-Agents Toolkit to train and run machine-learning agents in Unity projects. |
3 | 3 |
|
4 | | -1. Install Unity (6000.0 or later) |
5 | | -2. Install Python (>= 3.10.1, <=3.10.12) - we recommend using 3.10.12 |
6 | | -3. Install the `com.unity.ml-agents` Unity package; or clone this repository and install locally (recommended for the latest version and bug fixes) |
7 | | -4. Install `mlagents-envs` |
8 | | -5. Install `mlagents` |
| 4 | +This process includes installing Unity, configuring Python, and installing the ML-Agents packages. Follow the steps in order to ensure compatibility between Unity and the ML-Agents components. |
9 | 5 |
|
10 | | -### Install **Unity 6000.0** or Later |
11 | 6 |
|
12 | | -[Download](https://unity3d.com/get-unity/download) and install Unity. We strongly recommend that you install Unity through the Unity Hub as it will enable you to manage multiple Unity versions. |
13 | 7 |
|
14 | | -### Install **Python 3.10.12** |
| 8 | +## Install Unity |
15 | 9 |
|
16 | | -We recommend [installing](https://www.python.org/downloads/) Python 3.10.12. If you are using Windows, please install the x86-64 version and not x86. If your Python environment doesn't include `pip3`, see these [instructions](https://packaging.python.org/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers) on installing it. We also recommend using [conda](https://docs.conda.io/en/latest/) or [mamba](https://github.com/mamba-org/mamba) to manage your python virtual environments. |
| 10 | +Install Unity 6000.0 or later to use the ML-Agents Toolkit. |
17 | 11 |
|
18 | | -#### Conda python setup |
| 12 | +To install Unity, follow these steps: |
19 | 13 |
|
20 | | -Once conda has been installed in your system, open a terminal and execute the following commands to setup a python 3.10.12 virtual environment and activate it. |
| 14 | +1. [Download Unity](https://unity3d.com/get-unity/download). |
| 15 | +2. Use **Unity Hub** to manage installations and versions. |
| 16 | + Unity Hub makes it easier to manage multiple Unity versions and associated projects. |
| 17 | +3. Verify that the Unity Editor version is 6000.0 or later. |
21 | 18 |
|
22 | | -```shell |
23 | | -conda create -n mlagents python=3.10.12 && conda activate mlagents |
24 | | -``` |
25 | | - |
26 | | -### Install the `com.unity.ml-agents` Unity package |
| 19 | +## Install Python 3.10.12 using Conda |
27 | 20 |
|
28 | | -The Unity ML-Agents C# SDK is a Unity Package. You can install the `com.unity.ml-agents` package [directly from the Package Manager registry](https://docs.unity3d.com/Manual/upm-ui-install.html). Please make sure you enable 'Preview Packages' in the 'Advanced' dropdown in order to find the latest Preview release of the package. |
| 21 | +Use Conda or Mamba to install and manage your Python environment. This ensures that ML-Agents dependencies are isolated and version-controlled. |
29 | 22 |
|
30 | | -**NOTE:** If you do not see the ML-Agents package listed in the Package Manager please follow the advanced installation instructions below. |
| 23 | +To install Python, follow these steps: |
31 | 24 |
|
32 | | -#### Advanced: Local Installation for Development |
| 25 | +1. Install [Conda](https://docs.conda.io/en/latest/) or [Mamba](https://github.com/mamba-org/mamba). |
| 26 | +2. Open a terminal and create a new Conda environment with Python 3.10.12: |
33 | 27 |
|
34 | | -You will need to clone the repository if you plan to modify or extend the ML-Agents Toolkit for your purposes, or if you'd like to download our example environments. Some of our tutorials / guides assume you have access to our example environments. |
| 28 | + ```shell |
| 29 | + conda create -n mlagents python=3.10.12 && conda activate mlagents |
35 | 30 |
|
36 | | -Use the command below to clone the repository |
| 31 | +3. On **Windows**, install PyTorch separately to ensure CUDA support: |
37 | 32 |
|
38 | | -```sh |
39 | | -git clone --branch release_23 https://github.com/Unity-Technologies/ml-agents.git |
| 33 | +```shell |
| 34 | +pip3 install torch~=2.2.1 --index-url https://download.pytorch.org/whl/cu121 |
40 | 35 | ``` |
| 36 | +If prompted, install Microsoft Visual C++ Redistributable. For more installation options and versions, refer to the [PyTorch installation guide](https://pytorch.org/get-started/locally/). |
41 | 37 |
|
42 | | -The `--branch release_23` option will switch to the tag of the latest stable release. Omitting that will get the `develop` branch which is potentially unstable. However, if you find that a release branch does not work, the recommendation is to use the `develop` branch as it may have potential fixes for bugs and dependency issues. |
43 | 38 |
|
44 | | -(Optional to get bleeding edge) |
| 39 | +## Install ML-Agents |
| 40 | +You can install ML-Agents in two ways: |
45 | 41 |
|
46 | | -```sh |
47 | | -git clone https://github.com/Unity-Technologies/ml-agents.git |
48 | | -``` |
| 42 | +* [Package installation](#install-ml-agents-package-installation): Recommended for most users who want to use ML-Agents without modifying the source code or using the example environments. |
| 43 | +* [Advanced installation](#install-ml-agents-advanced-installation): For contributors, developers extending ML-Agents, or users who want access to the example environments. |
49 | 44 |
|
50 | | -If you plan to contribute those changes back, make sure to clone the `develop` branch (by omitting `--branch release_23` from the command above). See our [Contributions Guidelines](CONTRIBUTING.md) for more information on contributing to the ML-Agents Toolkit. |
| 45 | +### Install ML-Agents (Package installation) |
51 | 46 |
|
52 | | -You can [add the local](https://docs.unity3d.com/Manual/upm-ui-local.html) `com.unity.ml-agents` package (from the repository that you just cloned) to your project by: |
| 47 | +Use this method if you don’t plan to modify the toolkit or need the example environments. |
53 | 48 |
|
54 | | -1. navigating to the menu `Window` -> `Package Manager`. |
55 | | -2. In the package manager window click on the `+` button on the top left of the packages list). |
56 | | -3. Select `Add package from disk...` |
57 | | -4. Navigate into the `com.unity.ml-agents` folder. |
58 | | -5. Select the `package.json` file. |
| 49 | +#### Install the ML-Agents Unity package |
| 50 | + |
| 51 | +To install the package, follow these steps: |
| 52 | + |
| 53 | +1. In Unity, open **Window** > **Package Manager**. |
| 54 | +2. Select **+** > **Add package by name**. |
| 55 | +3. Enter `com.unity.ml-agents`. |
| 56 | +4. Enable **Preview Packages** under the **Advanced** drop-down list if the package doesn’t appear. |
| 57 | + |
| 58 | +If the package isn’t listed, follow the [Advanced Installation](#install-ml-agents-advanced-installation) method instead. |
59 | 59 |
|
60 | | -<p align="center"> <img src="images/unity_package_manager_window.png" alt="Unity Package Manager Window" height="150" border="10" /> <img src="images/unity_package_json.png" alt="package.json" height="150" border="10" /> </p> |
61 | 60 |
|
62 | | -If you are going to follow the examples from our documentation, you can open the |
63 | | -`Project` folder in Unity and start tinkering immediately. |
64 | 61 |
|
65 | | -### Install Python package |
| 62 | +#### Install the ML-Agents Python package |
66 | 63 |
|
67 | | -Installing the `mlagents` Python package involves installing other Python packages that `mlagents` depends on. So you may run into installation issues if your machine has older versions of any of those dependencies already installed. Consequently, our supported path for installing `mlagents` is to leverage Python Virtual Environments. Virtual Environments provide a mechanism for isolating the dependencies for each project and are supported on Mac / Windows / Linux. We offer a dedicated [guide on Virtual Environments](Using-Virtual-Environment.md). |
| 64 | +Install the ML-Agents Python package to enable communication between Unity and your machine learning training environment. |
68 | 65 |
|
69 | | -#### Installing `mlagents` from PyPi |
| 66 | +Using a Python virtual environment helps isolate project dependencies and prevent version conflicts across your system. Virtual environments are supported on macOS, Windows, and Linux. For more information, refer to [Using Virtual Environments](Using-Virtual-Environment.md). |
70 | 67 |
|
71 | | -You can install the ML-Agents Python package directly from PyPi. This is the recommended approach if you installed the C# package via the Package Manager registry. |
| 68 | +1. Before installing ML-Agents, activate the Conda environment you created. |
72 | 69 |
|
73 | | -**Important:** Ensure you install a Python package version that matches your Unity package version. Check the [release history](https://github.com/Unity-Technologies/ml-agents/releases) to find compatible versions. |
74 | 70 |
|
75 | | -To install, activate your virtual environment and run the following command: |
| 71 | +2. Install the ML-Agents Python package from the Python Package Index (PyPI): |
76 | 72 |
|
77 | 73 | ```shell |
78 | 74 | python -m pip install mlagents==1.1.0 |
79 | 75 | ``` |
| 76 | +Make sure to install a Python package version that matches your Unity ML-Agents package version. For information on compatible versions, refer to the [ML-Agents release history](https://github.com/Unity-Technologies/ml-agents/releases). |
80 | 77 |
|
81 | | -which will install the latest version of ML-Agents Python packages and associated dependencies available on PyPi. If building the wheel for `grpcio` fails, run the following command before installing `mlagents` with pip: |
| 78 | +3. If you encounter an error while building the `grpcio` wheel, install it separately before reinstalling `mlagents`: |
82 | 79 |
|
83 | 80 | ```shell |
84 | 81 | conda install "grpcio=1.48.2" -c conda-forge |
85 | 82 | ``` |
| 83 | +This step resolves dependency conflicts that can occur with older versions of `grpcio`. |
86 | 84 |
|
87 | | -When you install the Python package, the dependencies listed in the [setup.py file](https://github.com/Unity-Technologies/ml-agents/blob/release/4.0.0/ml-agents/setup.py) are also installed. These include [PyTorch](Background-PyTorch.md). |
| 85 | +4. When the installation completes successfully, all the required Python dependencies listed in the [setup.py file](https://github.com/Unity-Technologies/ml-agents/blob/release/4.0.0/ml-agents/setup.py), including [PyTorch](Background-PyTorch.md) are automatically configured. |
88 | 86 |
|
89 | 87 |
|
90 | | -#### Advanced: Local Installation for Development |
| 88 | +### Install ML-Agents (Advanced Installation) |
91 | 89 |
|
92 | | -##### (Windows) Installing PyTorch |
| 90 | +Use the advanced installation method if you plan to modify or extend the ML-Agents Toolkit, or if you want to download and use the example environments included in the repository. |
93 | 91 |
|
94 | | -On Windows, you'll have to install the PyTorch package separately prior to installing ML-Agents in order to make sure the cuda-enabled version is used, rather than the CPU-only version. Activate your virtual environment and run from the command line: |
| 92 | +#### Clone the ML-Agents repository |
| 93 | + |
| 94 | +Clone the ML-Agents repository to access the source code, sample environments, and development branches. |
| 95 | + |
| 96 | +To clone the latest stable release, run: |
95 | 97 |
|
96 | 98 | ```sh |
97 | | -pip3 install torch~=2.2.1 --index-url https://download.pytorch.org/whl/cu121 |
| 99 | +git clone --branch release_23 https://github.com/Unity-Technologies/ml-agents.git |
98 | 100 | ``` |
99 | 101 |
|
100 | | -Note that on Windows, you may also need Microsoft's Visual C++ Redistributable if you don't have it already. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/) for more installation options and versions. |
| 102 | +The `--branch release_23` flag checks out the latest stable release. |
| 103 | +If you omit this option, the `develop` branch is cloned instead, which may contain experimental or unstable changes. |
| 104 | +If the release branch does not work as expected, switch to the develop branch. It may include fixes for dependency or compatibility issues. |
| 105 | +To clone the bleeding-edge development version (optional), run: |
| 106 | +```sh |
| 107 | +git clone https://github.com/Unity-Technologies/ml-agents.git |
| 108 | +``` |
| 109 | +If you plan to contribute your changes, clone the develop branch (omit the `--branch` flag) and refer to the [Contribution Guidelines](CONTRIBUTING.md) for details. |
| 110 | + |
| 111 | + |
| 112 | +#### Add the ML-Agents Unity package |
| 113 | + |
| 114 | +After cloning the repository, add the `com.unity.ml-agents` Unity package to your project. |
| 115 | + |
| 116 | +To add the local package, follow these steps: |
| 117 | + |
| 118 | +1. In the Unity Editor, go to **Window** > **Package Manager**. |
| 119 | +2. In the **Package Manager** window, select **+**. |
| 120 | +3. Select **Add package from disk**. |
| 121 | +4. Navigate to the cloned repository and open the `com.unity.ml-agents` folder. |
| 122 | +5. Select the `package.json` file. |
101 | 123 |
|
102 | | -##### All Platforms |
| 124 | +Unity adds the ML-Agents package to your project. |
103 | 125 |
|
104 | | -To install the `mlagents` Python package, activate your virtual environment and run from the command line: |
| 126 | +If you plan to use the example environments provided in the repository, open the **Project** folder in Unity to explore and experiment with them. |
| 127 | + |
| 128 | + |
| 129 | +<p align="center"> <img src="images/unity_package_manager_window.png" alt="Unity Package Manager Window" height="150" border="10" /> <img src="images/unity_package_json.png" alt="package.json" height="150" border="10" /> </p> |
| 130 | + |
| 131 | + |
| 132 | +#### Install the ML-Agents Python package |
| 133 | + |
| 134 | +Install the Python packages from the cloned repository to enable training and environment communication. |
| 135 | + |
| 136 | +1. From the root of the cloned repository, activate your virtual environment and run: |
105 | 137 |
|
106 | 138 | ```sh |
107 | 139 | cd /path/to/ml-agents |
108 | 140 | python -m pip install ./ml-agents-envs |
109 | 141 | python -m pip install ./ml-agents |
110 | 142 | ``` |
111 | 143 |
|
112 | | -Note that this will install `mlagents` from the cloned repository, _not_ from the PyPi repository. If you installed this correctly, you should be able to run `mlagents-learn --help`, after which you will see the command line parameters you can use with `mlagents-learn`. |
| 144 | +This installs the ML-Agents packages directly from the cloned source, _not_ from PyPi. |
113 | 145 |
|
| 146 | +2. To confirm a successful installation, run: |
| 147 | +`mlagents-learn --help` |
114 | 148 |
|
| 149 | +If the command lists available parameters, your setup is complete. |
115 | 150 |
|
116 | | -If you intend to make modifications to `mlagents` or `mlagents_envs`, from the repository's root directory, run: |
| 151 | +3. If you plan to modify the ML-Agents source code or contribute changes, install the packages in editable mode. |
| 152 | +Editable installs let you make live changes to the Python files and test them immediately. |
| 153 | + |
| 154 | +From the repository’s root directory, run: |
117 | 155 |
|
118 | 156 | ```sh |
119 | 157 | pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html |
120 | 158 | pip3 install -e ./ml-agents-envs |
121 | 159 | pip3 install -e ./ml-agents |
122 | 160 | ``` |
123 | 161 |
|
124 | | -Running pip with the `-e` flag will let you make changes to the Python files directly and have those reflected when you run `mlagents-learn`. It is important to install these packages in this order as the `mlagents` package depends on `mlagents_envs`, and installing it in the other order will download `mlagents_envs` from PyPi. |
| 162 | +Note: |
| 163 | + |
| 164 | +Install the packages in this order. The `mlagents` package depends on `mlagents_envs`. |
| 165 | +Installing them in the other order will download `mlagents_envs` from PyPi, which can cause version mismatches. |
0 commit comments