Search Unity

Bug "TypeError: Descriptors cannot be created directly" error when running mlagents-learn

Discussion in 'ML-Agents' started by al3xj3ns3n, Feb 13, 2023.

  1. al3xj3ns3n

    al3xj3ns3n

    Joined:
    Sep 10, 2018
    Posts:
    21
    Been following the installation steps https://github.com/Unity-Technologies/ml-agents/blob/release_18_docs/docs/Installation.md and currently I'm getting stuck on the Installing mlagents step, after installation when I try running mlagents-learn --help I see this in the cmd:


    Traceback (most recent call last):
    File "C:\Users\Jax\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "C:\Users\Jax\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\python-envs\ml-env\Scripts\mlagents-learn.exe\__main__.py", line 5, in <module>
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\learn.py", line 2, in <module>
    from mlagents import torch_utils
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents\torch_utils\__init__.py", line 1, in <module>
    from mlagents.torch_utils.torch import torch as torch # noqa
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents\torch_utils\torch.py", line 6, in <module>
    from mlagents.trainers.settings import TorchSettings
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\settings.py", line 25, in <module>
    from mlagents.trainers.cli_utils import StoreConfigFile, DetectDefault, parser
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\cli_utils.py", line 5, in <module>
    from mlagents_envs.environment import UnityEnvironment
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents_envs\environment.py", line 34, in <module>
    from mlagents_envs.communicator_objects.command_pb2 import STEP, RESET
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\mlagents_envs\communicator_objects\command_pb2.py", line 32, in <module>
    _descriptor.EnumValueDescriptor(
    File "d:\users\jax\documents\work\projects\machine learning\python-envs\ml-env\lib\site-packages\google\protobuf\descriptor.py", line 755, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
    TypeError: Descriptors cannot not be created directly.
    If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
    If you cannot immediately regenerate your protos, some other possible workarounds are:
    1. Downgrade the protobuf package to 3.20.x or lower.
    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

    More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
     
  2. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    Did you install into a brand-new python virtual environment, or into an existing python environment?

    If into an existing python environment, you might consider creating a new virtual environment, and installing into that. Or downgrading protobuf to 3.20.3.
     
  3. al3xj3ns3n

    al3xj3ns3n

    Joined:
    Sep 10, 2018
    Posts:
    21
    I believe I installed into a brand-new python virtual environment, I have more experience with Unity than with python, I'm not sure how to go about downgrading protobuf. I'm also still seeing the "WARNING: You are using pip version 19.2.3, however version 23.0 is available" message even though I've already ran the upgrade pip command on the vm.
     
  4. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    - `pip install -U pip` to upgrade pip, I uusllay do `pip install -U pip wheel`, to get both out of the way
    - `pip install protobuf==3.20.3` to downgrade protobuf
    - are you sure you acitvated your enviornment by the way?
    - on linux and mac you can do `which python` and `which pip` to check whether the enviornemtn is activated . I'm not sure how to do that on windows though :p
    - you can do `pip freeze` to list all installed python packages
    - to activate your python environment, say you created venv at `venv`. so do `source`, oh wait thats linux. I dont know how to activate windows python enviornments, sorry :p
     
  5. al3xj3ns3n

    al3xj3ns3n

    Joined:
    Sep 10, 2018
    Posts:
    21
    I'm following the Virtual Environment setup here https://github.com/Unity-Technologi...ase_18_docs/docs/Using-Virtual-Environment.md and I'm pretty certain I'm activating the environment correctly. I ran pip install protobuf==3.20.3 and I'm seeing a different error now when I run mlagents-learn --help


    Traceback (most recent call last):
    File "C:\Users\Jax\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "C:\Users\Jax\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\Scripts\mlagents-learn.exe\__main__.py", line 4, in <module>
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\learn.py", line 13, in <module>
    from mlagents.trainers.trainer_controller import TrainerController
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\trainer_controller.py", line 13, in <module>
    from mlagents.trainers.env_manager import EnvManager, EnvironmentStep
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\env_manager.py", line 12, in <module>
    from mlagents.trainers.policy import Policy
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\policy\__init__.py", line 1, in <module>
    from mlagents.trainers.policy.policy import Policy # noqa
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\policy\policy.py", line 10, in <module>
    from mlagents.trainers.buffer import AgentBuffer
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\buffer.py", line 97, in <module>
    class AgentBufferField(list):
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\mlagents\trainers\buffer.py", line 211, in AgentBufferField
    self, pad_value: np.float = 0, dtype: np.dtype = np.float32
    File "D:\Users\Jax\Documents\Work\Projects\Machine Learning\Machine Learning\python-envs\ml-env\lib\site-packages\numpy\__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
    AttributeError: module 'numpy' has no attribute 'float'.
    `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
    The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
     
  6. al3xj3ns3n

    al3xj3ns3n

    Joined:
    Sep 10, 2018
    Posts:
    21
    Think I figured it out, it was running the wrong version of python even after uninstalling, script is running correctly now.
     
  7. nolink3

    nolink3

    Joined:
    Feb 9, 2023
    Posts:
    1
    Hello, i have the same problem. can you please tell me how you figured it out with a bit more detail?
    while i was trying to install ML Agents i uninstalled my new python version via the installer and then installed the older version (3.9.13 | 64bit).
    The CMD currently shows that the python version is 3.9.13 (which i want) & i also have an active virtual environment.

    I Typed:

    (venv) F:\UnityProjects\MachineLearning>mlagents-learn --help

    Error I Got:

    Traceback (most recent call last):
    File "C:\Users\User\venv\Scripts\mlagents-learn-script.py", line 33, in <module>
    sys.exit(load_entry_point('mlagents==0.30.0', 'console_scripts', 'mlagents-learn')())
    File "C:\Users\User\venv\Scripts\mlagents-learn-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()
    File "F:\python old\lib\importlib\metadata.py", line 86, in load
    module = import_module(match.group('module'))
    File "F:\python old\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
    File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 850, in exec_module
    File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
    File "C:\Users\User\venv\lib\site-packages\mlagents\trainers\learn.py", line 2, in <module>
    from mlagents import torch_utils
    File "C:\Users\User\venv\lib\site-packages\mlagents\torch_utils\__init__.py", line 1, in <module>
    from mlagents.torch_utils.torch import torch as torch # noqa
    File "C:\Users\User\venv\lib\site-packages\mlagents\torch_utils\torch.py", line 6, in <module>
    from mlagents.trainers.settings import TorchSettings
    File "C:\Users\User\venv\lib\site-packages\mlagents\trainers\settings.py", line 25, in <module>
    from mlagents.trainers.cli_utils import StoreConfigFile, DetectDefault, parser
    File "C:\Users\User\venv\lib\site-packages\mlagents\trainers\cli_utils.py", line 5, in <module>
    from mlagents_envs.environment import UnityEnvironment
    File "C:\Users\User\venv\lib\site-packages\mlagents_envs\environment.py", line 12, in <module>
    from mlagents_envs.side_channel.side_channel import SideChannel
    File "C:\Users\User\venv\lib\site-packages\mlagents_envs\side_channel\__init__.py", line 5, in <module>
    from mlagents_envs.side_channel.default_training_analytics_side_channel import ( # noqa
    File "C:\Users\User\venv\lib\site-packages\mlagents_envs\side_channel\default_training_analytics_side_channel.py", line 7, in <module>
    from mlagents_envs.communicator_objects.training_analytics_pb2 import (
    File "C:\Users\User\venv\lib\site-packages\mlagents_envs\communicator_objects\training_analytics_pb2.py", line 35, in <module>
    _descriptor.FieldDescriptor(
    File "C:\Users\User\venv\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
    TypeError: Descriptors cannot not be created directly.
    If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
    If you cannot immediately regenerate your protos, some other possible workarounds are:
    1. Downgrade the protobuf package to 3.20.x or lower.
    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

    More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates


    I also typed "(venv) F:\UnityProjects\MachineLearning>mlagents-learn". It didn't work either
     
  8. al3xj3ns3n

    al3xj3ns3n

    Joined:
    Sep 10, 2018
    Posts:
    21


    I was only able to get things working after switching the python version to 3.7.0, any other version was having problems.
     
  9. KVTeja_512

    KVTeja_512

    Joined:
    Apr 19, 2021
    Posts:
    4
    Which version of python were you using? What with what version of python did it work. I am using Python 3.10.11 which doesn't work.
     
  10. unity_32EB8E43D45034875653

    unity_32EB8E43D45034875653

    Joined:
    Apr 25, 2023
    Posts:
    1
    it's an error with protobuf ( protocol buffers ) library
    just do
    pip install protobuf==3.20
     
    bhunterd likes this.
  11. ice_creamer

    ice_creamer

    Joined:
    Jul 28, 2022
    Posts:
    34
    I training my agent,there is two behavior(forward and rotation). When i start, a warnning is appearing as below:
    ml-agents-release_17\ml-agents\mlagents\trainers\torch\utils.py:314: UserWarning: The use of `x.T` on tensors of dimension other than 2 to reverse their shape is deprecated and it will throw an error in a future release. Consider `x.mT` to transpose batches of matricesor `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse the dimensions of a tensor. (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\TensorShape.cpp:2318.)

    And my agent continues rotating and not go forward.
     
  12. ucax217

    ucax217

    Joined:
    Nov 8, 2018
    Posts:
    8
    ml-agents-release_17 is an old version. Maybe try a more recent one ...