Search Unity

Question Does the ML Agents python install work with Python 3.9?

Discussion in 'ML-Agents' started by ChartObserver, Oct 6, 2022.

  1. ChartObserver

    ChartObserver

    Joined:
    Dec 24, 2020
    Posts:
    7
    I have python 3.9.13 installed, but the repo recommends 3.6 or 3.7 version. Will I need to go back to one of those versions in order to install and run the ML Agents?
     
  2. MidnightGameDeveloper

    MidnightGameDeveloper

    Joined:
    Apr 26, 2014
    Posts:
    122
    Yes, this works. I did install Python 3.9.13 for ml-agents lately and I am using it with Unity 2021 and mlagents version 0.29.0 without any problems
     
    ChartObserver likes this.
  3. ChartObserver

    ChartObserver

    Joined:
    Dec 24, 2020
    Posts:
    7
    Thanks for the response. I'm curious how you got this to work. I pulled ML Agents release 19 from the repo at https://github.com/Unity-Technologies/ml-agents/tree/release_19

    There were problems with pytorch that I was not able to resolve. The docs page says to run this command:
    pip3 install torch~=1.7.1 -f https://download.pytorch.org/whl/torch_stable.html

    That fails with an error that pytorch 1.7.1 is no longer available. So I installed the oldest available pytorch, which is 1.9.0 version. However, the mlagents install fails with a message indicating this pytorch is not <1.9.0 and >=1.8.0

    Is there a workaround for this? I'm running python 3.9.6 on an M1 Mac, 12.6 (Monterey).
     
  4. ChartObserver

    ChartObserver

    Joined:
    Dec 24, 2020
    Posts:
    7
    I'm beginning to think that this is an M1 Mac problem. There are pytorch 1.8.1 versions listed on https://download.pytorch.org/whl/torch_stable.html but pip is not considering those (incompatibility issue with M1 arm processor?). Is it possible to tell pip to install ml-agents while ignoring the pytorch version dependency? Or will ml-agents fail with pytorch >= 1.9.0?
     
  5. MidnightGameDeveloper

    MidnightGameDeveloper

    Joined:
    Apr 26, 2014
    Posts:
    122
    I only use the repo do download the example project, the installation can be done via terminal commands (that's how I did it).
    I did use use pytorch 1.8.1 on my windows 10 pc. On my intel Mac I am still using an older version of python, so I can't really help you with that.
     
    ChartObserver likes this.
  6. MidnightGameDeveloper

    MidnightGameDeveloper

    Joined:
    Apr 26, 2014
    Posts:
    122
  7. ChartObserver

    ChartObserver

    Joined:
    Dec 24, 2020
    Posts:
    7
    Ah, that makes sense. I had a feeling that pytorch 1.8 was the right choice.

    By pulling the repo, I was able to edit the setup.py script locally, and that defines the parameters that pip uses to install the mlagents as a module. Then I told pip to install from my local copy, rather than defaulting to the public repo.
    Code (csharp):
    1. python -m pip install -e ~/Development/unity/ml-agents-release_19/ml-agents

    In case that helps anyone else, the setup file is located at ml-agents-release_19/ml-agents/setup.py and my edit is on line 71:
    Code (csharp):
    1.  ">>>>>>>torch>=1.8.0,<1.9.0;(platform_system!='Windows' and python_version>='3.9')
    2. "torch>=1.8.0,<1.10.0;(platform_system!='Windows' and python_version>='3.9')"
    I should point out that my solution assumes that ml-agents will work correctly with the pytorch 1.9.1 versiob that I was able to successfully install on my M1 Mac. However, I have no idea if that version actually compatible. So far it seems to be working correctly for me. So I opened a request on the Github repo asking that the setup.py be edited to reflect the full range of current compatible versions. Hopefully the maintainer can verify this and make any necessary changes.
     
    MidnightGameDeveloper likes this.