From 25d71a9a03d3d71b77b5ec143d5e61935d93dfa4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Jan 2025 20:13:47 +0530 Subject: [PATCH] Update train.mdx --- units/en/unitbonus1/train.mdx | 51 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/units/en/unitbonus1/train.mdx b/units/en/unitbonus1/train.mdx index 4b911b7..cbc5a2f 100644 --- a/units/en/unitbonus1/train.mdx +++ b/units/en/unitbonus1/train.mdx @@ -64,15 +64,62 @@ Before diving into the notebook, you need to: GPU Step 2 -## Clone the repository and install the dependencies 🔽 +## Clone the repository 🔽 -- We need to clone the repository, that contains ML-Agents. +- We need to clone the repository, that contains **ML-Agents.** ```bash # Clone the repository (can take 3min) git clone --depth 1 https://github.com/Unity-Technologies/ml-agents ``` +## Setup the Virtual Environment 🔽 + +- In order for the **ML-Agents** to run successfully in Colab, Colab's Python version must meet the library's Python requirements. + +- We can check for the supported Python version under the `python_requires` parameter in the `setup.py` files. These files are required to set up the **ML-Agents** library for use and can be found in the following locations: + - `/content/ml-agents/ml-agents/setup.py` + - `/content/ml-agents/ml-agents-envs/setup.py` + +- Colab's Current Python version(can be checked using `!python --version`) doesn't match the library's `python_requires` parameter, as a result installation may silently fail and lead to errors like these, when executing the same commands later: + - `/bin/bash: line 1: mlagents-learn: command not found` + - `/bin/bash: line 1: mlagents-push-to-hf: command not found` + +- To resolve this, we'll create a virtual environment with a Python version compatible with the **ML-Agents** library. + +`Note:` *For future compatibility, always check the `python_requires` parameter in the installation files and set your virtual environment to the maximum supported Python version in the given below script if the Colab's Python version is not compatible* + +```bash +# Colab's Current Python Version (Incompatible with ML-Agents) +!python --version +``` + +```bash +# Install virtualenv and create a virtual environment +!pip install virtualenv +!virtualenv myenv + +# Download and install Miniconda +!wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh +!chmod +x Miniconda3-latest-Linux-x86_64.sh +!./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local + +# Activate Miniconda and install Python ver 3.10.12 +!source /usr/local/bin/activate +!conda install -q -y --prefix /usr/local python=3.10.12 ujson # Specify the version here + +# Set environment variables for Python and conda paths +!export PYTHONPATH=/usr/local/lib/python3.10/site-packages/ +!export CONDA_PREFIX=/usr/local/envs/myenv +``` + +```bash +# Python Version in New Virtual Environment (Compatible with ML-Agents) +!python --version +``` + +## Installing the dependencies 🔽 + ```bash # Go inside the repository and install the package (can take 3min) %cd ml-agents