Search Unity

'mlagents-learn' is not recognized as an internal or external command

Discussion in 'ML-Agents' started by LAdelg, Jun 16, 2020.

  1. LAdelg

    LAdelg

    Joined:
    Jan 31, 2020
    Posts:
    5
    I get the error message:
    'mlagents-learn' is not recognized as an internal or external command,
    operable program or batch file.

    when trying to run
    mlagents-learn config/trainer_config.yaml --run-id=MyFirstAI

    I'm using Python 3.8.3 Windows x64,
    I have the latest stable version of Unity,
    pip freeze shows ml-agents

    I'm missing something small, I know it.
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
    I'll forward this to the team for them to look into. Which version of ML Agents are you using?
     
  3. LAdelg

    LAdelg

    Joined:
    Jan 31, 2020
    Posts:
    5
    The package in unity says 1.0.2 but when I type pip3 show mlagents I get Version: 0.17.0
     
  4. BotAcademy

    BotAcademy

    Joined:
    May 15, 2020
    Posts:
    32
    That's okay. There is a python package and a unity package. U should use Version 1.1 in Unity though, since it is the compatible version for 0.17.0.

    Did you install mlagents via pip or self-build from sources? If latter, you need both, mlagents and mlagents-envs

    I have a tutorial where I go through it step by step (for Release 1 though) but it's basically the same for the newest version that you're using. Feel free to check it out.
     
    Last edited: Jun 26, 2020
  5. LAdelg

    LAdelg

    Joined:
    Jan 31, 2020
    Posts:
    5
    So I watched your video, updated to Unity ml agents 1.1.0, and then decided to uninstall and reinstall the ml agents python package through pip. The second time around I got this warning:

    WARNING: The scripts mlagents-learn.exe and mlagents-run-experiment.exe are installed in 'C:\Users\luked\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts' which is not on PATH.

    I reinstalled Python with the "include to path" and now I'm one step further.
    When I run "mlagents-learn config/trainer_config.yaml --run-id=MyFirstAI" in the correct directory I get a warning about not being able to utilize the gpu (which it says to ignore)

    and then later on

    Traceback (most recent call last):
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
    File "C:\Users\luked\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\mlagents-learn.exe\__main__.py", line 7, in <module>
    File "C:\Users\luked\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mlagents\trainers\learn.py", line 322, in main
    run_cli(parse_command_line())
    File "C:\Users\luked\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mlagents\trainers\learn.py", line 56, in parse_command_line
    return RunOptions.from_argparse(args)
    File "C:\Users\luked\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mlagents\trainers\settings.py", line 349, in from_argparse
    raise TrainerConfigError(
    mlagents.trainers.exception.TrainerConfigError: The option default was specified in your YAML file, but is invalid.

    I'm assuming the last line is important!


    I did not do anything to the mlagents-release folders after downloading them from github.
    I tried with release-1, release-2, and release-3


    EDIT:
    So I opened the trainer_config.yaml file and commented out the default option, only to find out that the next option, which happened to be FoodCollector, was also invalid. After commenting out all of the options other than 3DBall, it returned: The option 3DBall was specified in your YAML file, but is invalid, just like all the other options I commented. Are the yaml files in the mlagent-release github repos out of date? Every video I watch shows the YouTubers simply running the mlagents-learn command without editing the YAML file at all. I'm very new to all of this so I might be missing something easy.


    Also, simply running mlagents-learn without any additional parameters, still allows me to train the 3DBall model when I have unity open! weird
     
    Last edited: Jun 19, 2020
  6. BotAcademy

    BotAcademy

    Joined:
    May 15, 2020
    Posts:
    32
    Thats because you're pointing to a config file from Release 1 (trainer_config.yaml) but using Release 3. You get this error because the structure of the configuration changed with Release 3. Just use the config folder that comes with Release 3 and then use the following command when you're in the root of the release 3 folder to run the 3DBall environment:
    mlagents-learn ./config/ppo/3DBall.yaml --run-id whatever
     
    Mehrdad995 and celion_unity like this.
  7. LAdelg

    LAdelg

    Joined:
    Jan 31, 2020
    Posts:
    5
    Thanks so much!
     
  8. LAdelg

    LAdelg

    Joined:
    Jan 31, 2020
    Posts:
    5
    Back again! I'm trying to write my own yaml training_config file because the Unity Hummingbird course is out of date and I'm getting "the Hummingbird option is invalid" when I try to train. I followed the GitHub "Migrating" sections and I thought I moved all the lines into the new grouping format but I'm still getting "TrainerConfigError: The option trainer was specified in your YAML file for TrainerSettings, but is invalid."


    My config file------>

    (Sorry but the Unity forum .trim()'s every line so I had to use /t to show tabs (if its even important to the python scripts?))

    behaviors:
    /t Hummingbird:
    /t/t trainer: ppo
    /t/t hyperparameters:
    /t/t/t batch_size: 2048
    /t/t/t buffer_size: 20480
    /t/t/t learning_rate: 3.0e-4
    /t/t/t learning_rate_schedule: linear
    /t/t/t beta: 5.0e-3
    /t/t/t epsilon: 0.2
    /t/t/t lambd: 0.95
    /t/t/t num_epoch: 3
    .
    /t/t network_settings:
    /t/t/t normalize: false
    /t/t/t hidden_units: 256
    /t/t/t num_layers: 2
    /t/t/t vis_encode_type: simple
    /t/t/t memory:
    /t/t/t/t sequence_length: 64
    /t/t/t/t memory_size: 128
    .
    /t/t summary_freq: 10000

    /t/t reward_signals:
    /t/t/t extrinsic:
    /t/t/t/t strength: 1.0
    /t/t/t/t gamma: 0.99
    .
    /t/t time_horizon: 128
    .
    /t/t max_steps: 5.0e6


    I also tried this without the "behaviors:" so the top line read: "Hummingbird:" and it said "The option Hummingbird was specified in your YAML file for TrainerSettings, but is invalid."
     
    Last edited: Jun 25, 2020
  9. BotAcademy

    BotAcademy

    Joined:
    May 15, 2020
    Posts:
    32
    First of all, yes the tabs are important, cause it's a .yaml file. You need to rename trainer to trainer_type
     
  10. nidienibaba

    nidienibaba

    Joined:
    Oct 13, 2020
    Posts:
    1
    Hello, I followed the video instructions. But when I typed the mlagents-learn. Something happened, I dont know how to fix that.

    C:\Users\92959\anaconda3\envs\unity_rl\lib\site-packages\h5py\__init__.py:40: UserWarning: h5py is running against HDF5 1.10.5 when it was built against 1.10.4, this may cause problems
    '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
    Warning! ***HDF5 library version mismatched error***
    The HDF5 header files used to compile this application do not match
    the version used by the HDF5 library to which this application is linked.
    Data corruption or segmentation faults may occur if the application continues.
    This can happen when an application was compiled by one version of HDF5 but
    linked with a different version of static or shared HDF5 library.
    You should recompile the application or check your shared library related
    settings such as 'LD_LIBRARY_PATH'.
    You can, at your own risk, disable this warning by setting the environment
    variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
    Setting it to 2 or higher will suppress the warning messages totally.
    Headers are 1.10.4, library is 1.10.5
    SUMMARY OF THE HDF5 CONFIGURATION
    =================================
    General Information:
    -------------------
    HDF5 Version: 1.10.5
    Configured on: 2019-03-04
    Configured by: Visual Studio 15 2017 Win64
    Host system: Windows-10.0.17763
    Uname information: Windows
    Byte sex: little-endian
    Installation point: C:/Program Files/HDF5
    Compiling Options:
    ------------------
    Build Mode:
    Debugging Symbols:
    Asserts:
    Profiling:
    Optimization Level:
    Linking Options:
    ----------------
    Libraries:
    Statically Linked Executables: OFF
    LDFLAGS: /machine:x64
    H5_LDFLAGS:
    AM_LDFLAGS:
    Extra libraries:
    Archiver:
    Ranlib:
    Languages:
    ----------
    C: yes
    C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
    CPPFLAGS:
    H5_CPPFLAGS:
    AM_CPPFLAGS:
    CFLAGS: /DWIN32 /D_WINDOWS /W3
    H5_CFLAGS:
    AM_CFLAGS:
    Shared C Library: YES
    Static C Library: YES
    Fortran: OFF
    Fortran Compiler:
    Fortran Flags:
    H5 Fortran Flags:
    AM Fortran Flags:
    Shared Fortran Library: YES
    Static Fortran Library: YES
    C++: ON
    C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
    C++ Flags: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
    H5 C++ Flags:
    AM C++ Flags:
    Shared C++ Library: YES
    Static C++ Library: YES
    JAVA: OFF
    JAVA Compiler:
    Features:
    ---------
    Parallel HDF5: OFF
    Parallel Filtered Dataset Writes:
    Large Parallel I/O:
    High-level library: ON
    Threadsafety: OFF
    Default API mapping: v110
    With deprecated public symbols: ON
    I/O filters (external): DEFLATE DECODE ENCODE
    MPE:
    Direct VFD:
    dmalloc:
    Packages w/ extra debug output:
    API Tracing: OFF
    Using memory checker: OFF
    Memory allocation sanity checks: OFF
    Function Stack Tracing: OFF
    Strict File Format Checks: OFF
    Optimization Instrumentation:
    Bye...

    I tried both 1.10.4 and 1.10.5 hdf5, both were not working.
     
  11. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
    I'll ping the team for some guidance!
     
  12. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    Regarding the config file, I would recommend checking the exact version of mlagents you are using and copy an example yaml file from the same version. The formatting of the yaml sometimes changes as we add/remove features so it must be changed if the version changes.


    Regarding hdf5, the setup.py file of mlagents requires hdf5 version to be at minimum 2.9.0. I think you should upgrade that package.
     
  13. cjcamanch

    cjcamanch

    Joined:
    Apr 30, 2020
    Posts:
    8
    (venv) G:\UnityProj\cars1>mlagents-learn Assets\Karting\Prefabs\AI\kart_mg_trainer_config.yaml --train --run-id=custom-track-1 "mlagents-learn" is not internal or external command, executable program, or batch file. why is there such an error?
    (venv) G: \ UnityProj \ cars1 is the project folder.
     
    epiklife likes this.
  14. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    "mlagents-learn" is not internal or external command, executable program, or batch file. why is there such an error?

    This error is usually an installation issue. most likely the pip package was not installed properly. I would recommend uninstalling and reinstalling ml-agents's Python package via pip and even create a new virtual environment.
     
  15. cjcamanch

    cjcamanch

    Joined:
    Apr 30, 2020
    Posts:
    8
    Сompleted all steps of the lesson:
    1. Go to the Command Prompt (Windows) or Terminal (Mac/Linux)
      Run cd <directory-of-project>
    2. For Windows (you must have Python 3.7.7 or higher installed):
    3. Run python -m venv venv
    4. Run venv\Scripts\activate
    5. Run pip install -Iv mlagents==0.13.0
    Everything went well, it was written in red:

    "After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.

    We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

    tensorflow 2.0.3 requires numpy<1.19.0,>=1.16.0, but you'll have numpy 1.19.2 which is incompatible."

    How to fix it?
     
    Last edited: Oct 29, 2020
  16. ervteng_unity

    ervteng_unity

    Unity Technologies

    Joined:
    Dec 6, 2018
    Posts:
    150
    You can run pip install tensorflow --upgrade, which will install the latest Tensorflow 2.3.0, which won't have that version incompatibility. Or, run pip install numpy==1.16.0, which will install the older version of numpy.
     
  17. cjcamanch

    cjcamanch

    Joined:
    Apr 30, 2020
    Posts:
    8
    Now this error comes out, although everything that needs to be updated:
    "We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

    mlagents 0.13.0 requires tensorflow<2.1,>=1.7, but you'll have tensorflow 2.1.0 which is incompatible."
    Successfully installed gast-0.2.2 scipy-1.4.1 tensorboard-2.1.1 tensorflow-2.1.0 tensorflow-estimator-2.1.0
     
  18. ervteng_unity

    ervteng_unity

    Unity Technologies

    Joined:
    Dec 6, 2018
    Posts:
    150
    Hmm, I'd force the tensorflow version back to 2.0.3 (pip install tensorflow==2.0.3) and install the required version of numpy (pip install numpy==1.18.5).
     
  19. cjcamanch

    cjcamanch

    Joined:
    Apr 30, 2020
    Posts:
    8
    Everything seems to be fine,
    Successfully installed numpy-1.18.5 tensorboard-2.0.2 tensorflow-2.0.3 tensorflow-estimator-2.0.1
    but:
    (venv) G:\UnityProj\cars1>mlagent-learn Assets\Karting\Prefabs\AI\kart_mg_trainer_config.yaml --train --run-id-custom-track-1
    "mlagent-learn"
    is not internal or external command, executable program, or batch file.
    Maybe I'm not writing the path to the project folder so?
     
  20. ervteng_unity

    ervteng_unity

    Unity Technologies

    Joined:
    Dec 6, 2018
    Posts:
    150
    Command is mlagents-learn, with an S after mlagent.
     
  21. cjcamanch

    cjcamanch

    Joined:
    Apr 30, 2020
    Posts:
    8
  22. ervteng_unity

    ervteng_unity

    Unity Technologies

    Joined:
    Dec 6, 2018
    Posts:
    150
    Hmm, it is possible that the directory with the executable isn't in your Python path. How did you install Python? Was it using the original installer?
     
  23. efgt1995

    efgt1995

    Joined:
    Feb 20, 2020
    Posts:
    2
    I was facing the same problem, it seems that it was because of me using python 3.8, so I used python 3.7 (3.7.9 to be exact) instead. And before installing the mlagent==0.13.1 I downgraded h5py to 2.10.0 and numpy to 1.16.0.

    Now the mlagents-learn command is working fine for me.
     
    unity_Z32-r-X-tj3btQ likes this.
  24. Amo50X

    Amo50X

    Joined:
    Jul 23, 2020
    Posts:
    1
    Traceback (most recent call last):
    File "C:\Users\amoge\anaconda3\envs\unity-rl\Scripts\mlagents-learn-script.py", line 33, in <module>
    sys.exit(load_entry_point('mlagents', 'console_scripts', 'mlagents-learn')())
    File "C:\Users\amoge\anaconda3\envs\unity-rl\Scripts\mlagents-learn-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()
    File "C:\Users\amoge\anaconda3\envs\unity-rl\lib\importlib\metadata\__init__.py", line 162, in load
    module = import_module(match.group('module'))
    File "C:\Users\amoge\anaconda3\envs\unity-rl\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "c:\users\amoge\onedrive\desktop\ml-agents-main\ml-agents\mlagents\trainers\learn.py", line 2, in <module>
    from mlagents import torch_utils
    File "c:\users\amoge\onedrive\desktop\ml-agents-main\ml-agents\mlagents\torch_utils\__init__.py", line 1, in <module>
    from mlagents.torch_utils.torch import torch as torch # noqa
    File "c:\users\amoge\onedrive\desktop\ml-agents-main\ml-agents\mlagents\torch_utils\torch.py", line 30, in <module>
    assert_torch_installed()
    File "c:\users\amoge\onedrive\desktop\ml-agents-main\ml-agents\mlagents\torch_utils\torch.py", line 21, in assert_torch_installed
    assert torch_pkg is not None and LooseVersion(torch_pkg.version) >= LooseVersion(
    AssertionError: A compatible version of PyTorch was not installed. Please visit the PyTorch homepage (https://pytorch.org/get-started/locally/) and follow the instructions to install. Version 1.6.0 and later are supported.

    I keep getting this error every time I'm using "mlagents-learn" command.
    I have followed all instruction of to install PyTorch and Verification is success, but still having a problem