How to fix "ModuleNotFoundError: No module named 'ns3'" error after executing the example python in ns3?

I have this error when I execute the python program in ns3:

Traceback (most recent call last):
 File "/home/alyaa/ns-allinone-3.40/ns-3.40/tes1.py", line 1, in <module>
  import ns3
ModuleNotFoundError: No module named 'ns3'
Command 'python3 tes1.py' returned non-zero exit status 1.

Upvotes: -1

Views: 230

Answers (2)

Gabriel
Gabriel

Reputation: 136

If you execute test.py via the ns3 script, it will inject /home/alyaa/ns-allinone-3.40/ns-3.40/build/bindings/python to the PYTHONPATH environment variable, which allows you to import ns3.

You can manually do this using

export PYTHONPATH=/home/alyaa/ns-allinone-3.40/ns-3.40/build/bindings/python python3 tes1.py

Or you can do like ThanavCh suggested, and install the pip-packaged release (which is out-of-date because I've been waiting for cppyy to fix an issue introduced in version 3).

Upvotes: 0

ThanavCh
ThanavCh

Reputation: 1

Have you tried installing the module on your command line?

pip install ns3

Type that into command prompt on Windows / Terminal on Mac

Upvotes: 0

Related Questions