"Cannot import SUMO" with SUMO Installed

Hello,

I built my sumo from the source.

whereis sumo
sumo: /usr/local/bin/sumo /usr/share/sumo

Because I use zsh shell, I configured the sumo path in ~/.zshrc

export SUMO_HOME=/usr/share/sumo
export PYTHONPATH=$SUMO_HOME/tools:$PYTHONPATH

When I was installing the commonroad-scenario-designer, no error was reported. However, no matter I started crdesigner from the terminal or imported it as a python package, there was a warning saying

WARNING:root:Cannot import SUMO, simulation will not be offered in Scenario Designer

which disabled me to convert the commonroad files to sumo files.

Do you have any idea how to make the connection work? Thank you very much.

Which SUMO version and operating system are you using?

Note that we we have only tested it under Ubuntu.
For other operating systems, we can only provide limited support.

Yes, I am using Ubuntu 18.04. The SUMO version is 1.12.0.
Guess how I fixed this bug:

From SUMO-1.12.0, you no longer need to import libsumo, the lines

import libsumo as traci

in commonroad-sumo-interface/sumocr/interface/sumo-simulation.py and commonroad-sumo-interface/sumocr/interface/util.py should be revised to

import traci

I uninstalled sumocr, revised its source code, recompiled, and installed it manually.
Then, in toolkits/commonroad-scenario-designer/crdesigner/ui/gui/mwindow/toolboxes/obstacle_toolbox/obstacle_toolbox_ui.py, the try instruction muted one error. In fact, you have not implemented the rdesigner.api in line 17, so I muted this line. Then recompiled and installed it manually.
Tada~ It works now.

Plz put fewer lines in a try from now :wink:

1 Like

Can you provide more details about the issue with importing libsumo? I couldn’t reproduce the problem or find anything in the documentation/changelog of SUMO mentioning this change, where did you find the information that importing traci and libsumo is equivalent now? Importing traci might not solve the underlying problem, for instance when your versions of libsumo and SUMO do not match.

Here is my python3.7 importing libsumo and traci.

I checked pip3.7 freeze, but I am not sure which of these packages should match their version.

libsumo==1.12.0.post0
libtraci==1.12.0.post0
sumo==2.2.5
sumolib==1.12.0.post0

Here is a clue about why I import traci instead of libsumo.

Interfacing traci from Python
https://sumo.dlr.de/docs/TraCI/Interfacing_TraCI_from_Python.html

libsumo is actually a different (and faster) API compared to traci that just has a very similar python interface.
So the import should actually work, according to the error message there seems to be a problem with your SUMO installation since libproj is a dependency of SUMO. Also see here: Re: [sumo-user] libproj.so.12 Error

You are right. I try on another computer where SUMO was installed by apt command. There raises no error when I try to import libsumo.