i need to execute the examples written in python with ns3

434 views
Skip to first unread message

Alyaa “Researcher” Al_mula

unread,
Dec 30, 2023, 11:31:19 AM12/30/23
to ns-3-users
hello friends how can i execute the python examples in ns3, the ns3 doesnt recognize the module of ns .. please help me 

BENMADANI Houssem Eddine

unread,
Dec 30, 2023, 2:07:06 PM12/30/23
to ns-3-users
First, you have to make sure that Python Bindings is enabled. If not, enable it using this command:
./ns3 configure --enable-python-bindings

Then run the python example.
./ns3 run scratch/first.py

Alyaa “Researcher” Al_mula

unread,
Dec 30, 2023, 6:18:31 PM12/30/23
to ns-3-users
in fact thanks a lot, the python program is starting in execution, but after a while a got this error ( for all examples of python):  gmake: *** [Makefile:146: all] Error 2

i wish you help if you could please 

Tommaso Pecorella

unread,
Dec 30, 2023, 6:25:32 PM12/30/23
to ns-3-users
Simple question: did you read the tutorial and the installation guide?

Alyaa “Researcher” Al_mula

unread,
Dec 30, 2023, 6:52:49 PM12/30/23
to ns-3-users
yes but i did not understand all it, and there is commands didnt work with me 

Alyaa “Researcher” Al_mula

unread,
Dec 30, 2023, 6:58:17 PM12/30/23
to ns-3-users
this is line 146: $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all


On Sunday 31 December 2023 at 02:25:32 UTC+3 Tommaso Pecorella wrote:

Tommaso Pecorella

unread,
Dec 30, 2023, 11:05:55 PM12/30/23
to ns-3-users
I'm referring to this: https://www.nsnam.org/docs/installation/html/index.html

In order to run the python examples you have to successfully BUILD ns3.

Alyaa “Researcher” Al_mula

unread,
Dec 31, 2023, 10:15:20 AM12/31/23
to ns-3-users
i already build the ns3, and the examples of c++ it have been simulated successfully 

Alyaa “Researcher” Al_mula

unread,
Dec 31, 2023, 12:25:21 PM12/31/23
to ns-3-users
ok, i installed the libraries from this website and i got this: 
[ 99%] Linking CXX shared library ../../build/lib/libns3.40-aodv-test-default.so
[ 99%] Building CXX object utils/CMakeFiles/test-runner.dir/test-runner.cc.o
[100%] Linking CXX executable ../build/utils/ns3.40-test-runner-default
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.

Tommaso Pecorella

unread,
Dec 31, 2023, 8:51:50 PM12/31/23
to ns-3-users
Please check that you have the correct Cppyy version:
Python requires Cppyy, <https://cppyy.readthedocs.io/en/latest/installation.html> and specifically, version 2.4.2 is the latest version known to work with ns-3 at this time.
python3 -m pip install --user cppyy==2.4.2

moreover, check that the result of the configuration do state that python binding are enabled.

Alyaa “Researcher” Al_mula

unread,
Dec 31, 2023, 10:36:06 PM12/31/23
to ns-3-users
i checked the cmakechach.txt, and i found this : //Build ns-3 python bindings
NS3_PYTHON_BINDINGS:BOOL=ON

zeyad omar

unread,
Jan 1, 2024, 4:01:30 AM1/1/24
to ns-3-users
I had the same issue, I used pip install ns3 but didn't work until I found I was using the wrong python version (2.7) so I installed python 3.10 and typed pip install ns3 didn't work as well I typed python --version and got 2.7 that was the default version my system uses so I did this trick in my ubuntu terminal I typed "code ~/.bashrc" to open that file which controls how my terminal executes commands and I typed this line at the end of the file " alias python='/usr/local/bin/python3.10' " which means whenever I type python I mean python 3.10 when I did that I didn't get the NS3 no module found error but It took more than 30 minutes to run that simple script so I gave up on using python.

so to summarize:-
- in terminal write "code ~/.bashrc"
- add this line " alias python='/usr/local/bin/python3.10' " to the end of the file.
- save, close the file, and build NS3
- run your first python script

hope it helps
Reply all
Reply to author
Forward
0 new messages