I tried this and I am getting this error message.
import os
import sys
import traci
import optparse
# we need to import some python modules from the $SUMO_HOME/tools directory
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'")
from sumolib import checkBinary # Checks for the binary in environ vars
#sumoBinary = "C:/Program Files (x86)/Eclipse/Sumo/bin/sumo-gui.exe"
#sumoCmd = [sumoBinary, "-c", "crossroad.sumocfg","--start"]
# with open("traffic.rou.xml", "wb") as f:
def get_options():
opt_parser = optparse.OptionParser()
opt_parser.add_option("--nogui", action="store_true",
default=False, help="run the commandline version of sumo")
options, args = opt_parser.parse_args()
return options
# contains TraCI control loop
def run():
step = 0
count = 0
while traci.simulation.getMinExpectedNumber() > 0 and step < 200:
traci.simulationStep()
print('Step: ', step)
step += 1
vehID = traci.vehicle.getIDList()
print(traci.vehicle.getIDList())
count = count + vehID
print(traci.vehicle.getLaneID(vehID))
edges = traci.vehicle.getRoute(vehID)
index = traci.vehicle.getRouteIndex(vehID)
nextEdge = edges[index + 1]
laneID = traci.vehicle.getLane(vehID)
links = traci.lane.getLinks(laneID)
print(vehID)
print(count)
traci.close()
sys.stdout.flush()
# main entry point
if __name__ == "__main__":
options = get_options()
# check binary
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
print("TRaCI Starts Sumo")
# traci starts sumo as a subprocess and then this script connects and runs
traci.start([sumoBinary, "-c", "crossroad.sumocfg",
"--tripinfo-output", "tripinfo.xml"])
run()