com.unity.ml-agents/Documentation~/Installation.md
Set up your system to use the ML-Agents Toolkit to train and run machine-learning agents in Unity projects.
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.
Install Unity 6000.0 or later to use the ML-Agents Toolkit.
To install Unity, follow these steps:
Use Conda or Mamba to install and manage your Python environment. This ensures that ML-Agents dependencies are isolated and version-controlled.
To install Python, follow these steps:
Open a terminal and create a new Conda environment with Python 3.10.12:
conda create -n mlagents python=3.10.12 && conda activate mlagents
On Windows, install PyTorch separately to ensure CUDA support:
pip3 install torch~=2.2.1 --index-url https://download.pytorch.org/whl/cu121
If prompted, install Microsoft Visual C++ Redistributable. For more installation options and versions, refer to the PyTorch installation guide.
You can install ML-Agents in two ways:
Use this method if you don’t plan to modify the toolkit or need the example environments.
To install the package, follow these steps:
com.unity.ml-agents.If the package isn’t listed, follow the Advanced Installation method instead.
Install the ML-Agents Python package to enable communication between Unity and your machine learning training environment.
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.
Before installing ML-Agents, activate the Conda environment you created.
Install the ML-Agents Python package from the Python Package Index (PyPI):
python -m pip install mlagents==1.1.0
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.
grpcio wheel, install it separately before reinstalling mlagents:conda install "grpcio=1.48.2" -c conda-forge
This step resolves dependency conflicts that can occur with older versions of grpcio.
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.
Clone the ML-Agents repository to access the source code, sample environments, and development branches.
To clone the latest stable release, run:
git clone --branch release_23 https://github.com/Unity-Technologies/ml-agents.git
The --branch release_23 flag checks out the latest stable release.
If you omit this option, the develop branch is cloned instead, which may contain experimental or unstable changes.
If the release branch does not work as expected, switch to the develop branch. It may include fixes for dependency or compatibility issues.
To clone the bleeding-edge development version (optional), run:
git clone https://github.com/Unity-Technologies/ml-agents.git
If you plan to contribute your changes, clone the develop branch (omit the --branch flag) and refer to the Contribution Guidelines for details.
After cloning the repository, add the com.unity.ml-agents Unity package to your project.
To add the local package, follow these steps:
com.unity.ml-agents folder.package.json file.Unity adds the ML-Agents package to your project.
If you plan to use the example environments provided in the repository, open the Project folder in Unity to explore and experiment with them.
<p align="center"> </p>Install the Python packages from the cloned repository to enable training and environment communication.
cd /path/to/ml-agents
python -m pip install ./ml-agents-envs
python -m pip install ./ml-agents
This installs the ML-Agents packages directly from the cloned source, not from PyPi.
mlagents-learn --helpIf the command lists available parameters, your setup is complete.
From the repository’s root directory, run:
pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html
pip3 install -e ./ml-agents-envs
pip3 install -e ./ml-agents
Note:
Install the packages in this order. The mlagents package depends on mlagents_envs.
Installing them in the other order will download mlagents_envs from PyPi, which can cause version mismatches.