Unable to connect to 3DBall environment running in Unity [Win64]

I am trying to get started with ML Agents.

Here’s what I did on my Windows 10 machine in Unity:

In Python:

  • created new conda environment
  • in the environment run .\python.exe -m pip install mlagents “tensorflow==1.*” (successfully)
  • launched Python and run (code from the basic example notebook)
from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
from mlagents_envs.environment import UnityEnvironment

channel = EngineConfigurationChannel()
env = UnityEnvironment(base_port=5006, file_name=None, side_channels=[channel])

That printed “INFO:mlagents_envs:Listening on port 5006. Start training by pressing the Play button in the Unity Editor.”
So I hit Play button in the editor, and observed for a few minutes how some built-in agent juggled the balls.

The python, however, never connected. Eventually, I got an error message:

env = UnityEnvironment(base_port=5006, file_name=None, side_channels=[channel])
INFO:mlagents_envs:Listening on port 5006. Start training by pressing the Play button in the Unity Editor.
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\lost.conda\envs\mlagents\lib\site-packages\mlagents_envs\environment.py”, line 125, in init
aca_output = self.send_academy_parameters(rl_init_parameters_in)
File “C:\Users\lost.conda\envs\mlagents\lib\site-packages\mlagents_envs\environment.py”, line 512, in send_academy_parameters
return self.communicator.initialize(inputs)
File “C:\Users\lost.conda\envs\mlagents\lib\site-packages\mlagents_envs\rpc_communicator.py”, line 101, in initialize
self.poll_for_timeout()
File “C:\Users\lost.conda\envs\mlagents\lib\site-packages\mlagents_envs\rpc_communicator.py”, line 94, in poll_for_timeout
“The Unity environment took too long to respond. Make sure that :\n”
mlagents_envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
The environment does not need user interaction to launch
The Agents are linked to the appropriate Brains
The environment and the Python interface have compatible versions.

So the question is: what have I done wrong? I expected Python to connect to Unity and let me type next command line env.reset()

BTW, mlagents_envs.version is “0.13.1” as expected.

Hi,
Sorry, it looks like the ipynb that you got the example code from is out out date. The default editor port is 5004, not 5006. Can you try that out?

I made a PR to fix the docs here: Fix base port in ipynb example by chriselion · Pull Request #3283 · Unity-Technologies/ml-agents · GitHub

1 Like

Excellent, that solved the problem, and I can now list agent groups!

1 Like

Ah-ha! My Jupyter notebook was set to listen on port 5005. To fix, in step 3 add the base_port as such:

env = UnityEnvironment(base_port = 5004, file_name=env_name, side_channels = [engine_configuration_channel])
1 Like