Skip to content

Graceful exit when python bindings are not enabled

If we adopt a convention such as the following in our Python example programs:

-from ns import ns
+try:
+    from ns import ns
+except ModuleNotFoundError:
+    raise SystemExit("Error: ns Python module not found; Python bindings may not be enabled")

then we can turn this kind of feedback (when user mistakenly does not have Python bindings enabled):

[0/2] Re-checking globbed directories...
ninja: no work to do.
Traceback (most recent call last):
  File "examples/tutorial/first.py", line 16, in <module>
    from ns import ns
ModuleNotFoundError: No module named 'ns'
Command 'python3 examples/tutorial/first.py' returned non-zero exit status 1.

to this kind of clearer output message:

[0/2] Re-checking globbed directories...
ninja: no work to do.
Error: ns Python module not found; Python bindings may not be enabled
Command 'python3 examples/tutorial/first.py' returned non-zero exit status 1.

I thought of this while Gabriel was helping a user on the ns-3-users list this week. If there is support, I could write a full patch .