0

Trying to run the SUMO simulation using TraCI protocol:

import os, sys
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")

sumoBinary = "C:/Users/User/Desktop/Thesis_task/Trial_task/trial.sumocfg"
sumoCmd = [sumoBinary, "-c", "trial.sumocfg", '--log', 'logfile.txt'] 

import traci
traci.start(sumoCmd)
step = 0
while step < 1000:
    traci.simulationStep()
    if traci.inductionloop.getLastStepVehicleNumber("0") > 0:
        traci.trafficlight.setRedYellowGreenState("0", "GrGr") 
    step += 1

traci.close()

I am trying to connect the TraCI, but it is throwing this error:

OSError: [WinError 193] %1 is not a valid Win32 application

I have installed all the dependencies correctly, and also have the supporting Python version running on my machine. I followed a few older StackOverflow solutions, but none of them worked in my case.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

2 Answers2

0

Per the TraCI documentation:

Interfacing TraCI from Python

First you compose the command line to start either sumo or sumo-gui (leaving out the option which was needed before 0.28.0):

sumoBinary = "/path/to/sumo-gui"
sumoCmd = [sumoBinary, "-c", "yourConfiguration.sumocfg"]

However, your sumoBinary variable does not point to either of those two programs, instead it points to your trial.sumocfg file:

sumoBinary = "C:/Users/User/Desktop/Thesis_task/Trial_task/trial.sumocfg"

Which is clearly not an executable program, hence the error.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I just modify my Python code to point to the actual SUMO executable instead of the configuration file. – Paras_suthar Apr 11 '23 at 09:39
  • @Paras_suthar at the very least, you should upvote my answer, which lead you to your answer. See [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) And since you [posted your own answer](https://stackoverflow.com/help/self-answer), make sure you [accept it](https://stackoverflow.blog/2009/01/06/accept-your-own-answers/). – Remy Lebeau Apr 11 '23 at 16:45
  • I do not have enough reputation yet to upvote the answers. – Paras_suthar Apr 12 '23 at 21:09
0

I just modified my Python code to point out the actual SUMO executable instead of the configuration file.

sumoBinary = "sumo-gui"
sumoCmd = [sumoBinary, "-c", 
          "C:/Users/User/Desktop/Thesis_task/Trial_task/trial.sumocfg"]

Also added the SUMO bin directory to the system path so that it can be found by subprocess.

os.environ["PATH"] += os.pathsep + "C:/Program Files (x86)/Eclipse/Sumo/bin"

Now I can at least launch the sumo-gui without error. Thanks!