mlagents Nothing is working (python)

I tried installing everything needed, followed the docs.

  1. it says install python 3.7.2 or Higher. So I installed 3.10.9 (it was the lowest i could find).
  2. I tried installing PyTorch with “pip3 install torch~=1.7.1 -f https://download.pytorch.org/whl/torch_stable.html” than i got the first error[*1] it said there is now version 1.7 so I installed 1.11.0 (the lowest) this worked.
  3. than I used “pip install mlagents==0.30.0” how the docs said and got an error[*2] again so I installed 0.28.0 (the newest I could find) and it worked.
  4. than I tried “mlagents-learn --help” to check if everything works but it didn’t I got an error[*3] again. And this time I have no idea how to fix it.
    Now I don’t know what to do is this all just a buggy outdated mess or am I doing something wrong? I also have like 50 Errors in unity after Importing the example project but I think I can fix them.
    (Im using Win 11 and I also tried python 3.11)

[*1]

ERROR: No matching distribution found for torch~=1.7.1

[*2]

ERROR: Could not find a version that satisfies the requirement mlagents==0.30.0 (from versions: 0.4.0, 0.10.0.dev1, 0.10.0, 0.10.1, 0.11.0.dev0, 0.11.0, 0.12.0, 0.12.1, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.17.0, 0.18.0, 0.18.1, 0.19.0, 0.20.0, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.24.0, 0.24.1, 0.25.0, 0.25.1, 0.26.0, 0.27.0, 0.28.0)
ERROR: No matching distribution found for mlagents==0.30.0

[*3]

(venv) D:\Programme\Unity\AiCat>mlagents-learn --help
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "D:\Programme\Unity\AiCat\venv\Scripts\mlagents-learn.exe\__main__.py", line 4, in <module>
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\mlagents\trainers\learn.py", line 2, in <module>
from mlagents import torch_utils
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\mlagents\torch_utils\__init__.py", line 1, in <module>
from mlagents.torch_utils.torch import torch as torch # noqa
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\mlagents\torch_utils\torch.py", line 6, in <module>
from mlagents.trainers.settings import TorchSettings
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\mlagents\trainers\settings.py", line 644, in <module>
class TrainerSettings(ExportableSettings):
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\mlagents\trainers\settings.py", line 667, in TrainerSettings
cattr.register_structure_hook(
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\cattr\converters.py", line 207, in register_structure_hook
self._structure_func.register_cls_list([(cl, func)])
File "D:\Programme\Unity\AiCat\venv\lib\site-packages\cattr\dispatch.py", line 55, in register_cls_list
self._single_dispatch.register(cls, handler)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\functools.py", line 856, in register
raise TypeError(
TypeError: Invalid first argument to `register()`. typing.Dict[mlagents.trainers.settings.RewardSignalType, mlagents.trainers.settings.RewardSignalSettings] is not a class.

Per *2, you need python <=3.10.8. “0.30.0 Requires-Python >=3.8.13,<=3.10.8”. 0.30.0 is the latest verson. Thats the one you want.

1 Like

Can someone explain WHY? Is Python that bad that it causes breaking changes? Or is Unity the culprit?

Technically, it’s neither Unity, the engine, nor Python. The issue is the version constraints specified in mlagents setup.py ml-agents/ml-agents/setup.py at cc1a7501c4e09bea2c60722963bfdda7619ab908 · Unity-Technologies/ml-agents · GitHub It could actually be fixed in a couple of minutes. In fact, you could fix it, by creating a PR, that changes <=3.10.8 to <3.11.0, or really, since Python adheres pretty well to https://semver.org, could probably replace it with <4.0.0

I am trying to install ML Agents:
python -m pip install ./ml-agents-envs

When I try it with Python 3.9 I get:
ERROR: Package ‘mlagents-envs’ requires a different Python: 3.9.18 not in ‘<=3.10.12,>=3.10.1’

Ok so we need Python 3.10.

When I try it with Python 3.10 as the instructions say I get:
ERROR: Package ‘mlagents-envs’ requires a different Python: 3.10.13 not in ‘<=3.10.12,>=3.10.1’

Ok so we need Python 3.10.12 specifically.

When I try it with Python 3.10.12 I get:
Building wheel for numpy (pyproject.toml) … error
error: subprocess-exited-with-error
× Building wheel for numpy (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [287 lines of output]
setup.py:63: RuntimeWarning: NumPy 1.21.2 may not yet support Python 3.10.
warnings.warn(

i have the exact same issue

1 Like

Bumping the required version of numpy in the ml-agents\ml-agents-envs\setup file to 1.23.1 seems to have worked:
Before:
install_requires=[
“cloudpickle”,
“grpcio>=1.11.0,<=1.48.2”,
“Pillow>=4.2.1”,
“protobuf>=3.6,<3.20”,
“pyyaml>=3.1.0”,
“gym>=0.21.0”,
“pettingzoo==1.15.0”,
“numpy==1.21.2”,
“filelock>=3.4.0”,
],
After:
install_requires=[
“cloudpickle”,
“grpcio>=1.11.0,<=1.48.2”,
“Pillow>=4.2.1”,
“protobuf>=3.6,<3.20”,
“pyyaml>=3.1.0”,
“gym>=0.21.0”,
“pettingzoo==1.15.0”,
“numpy==1.23.1”,
“filelock>=3.4.0”,
],

1 Like

In which file did you find these lines of code? I think I checked everything, but I couldn’t find the configuration file

In your mlagents repo find the ml-agents-envs folder and open the setup text file. There you can change the numpy version that will get installed when you run the mlagents installation command. Change the numpy version to 1.23.1

1 Like

I encountered the same problem when trying to install MLagents in Colab or Kaggle Notebook (where it is generally very difficult to change the Python version).
The issue was resolved by adding an option to ignore Python version requirements:

pip install --ignore-requires-python mlagents==1.0.0

Maybe it will work with torch too