OS: MacOS Monterey 12.3.1, ns version: 3.36
First things first, make sure to update your OS, Xcode and Xcode tools before you proceed with the installation. Reasons (comes from my experience..):
- There are many compatibility issues concerning MacOS, updates can really help.
- If you want to do an update later when it's addressed. Sorry, the whole ns-3 you just built will not work anymore after a major update.
Some help in command lines:
$ xcode-select --install (install Xcode tools)
I need to use ns-3 in my Python simulation, maybe create some modules later. So my goal is to enable python bindings and API scanning (However during my installation ns launched 3.36 and there is no API Scanning anymore in configure status). The configuration should look like this:
PyViz visualizer : ON **If you need the visualization**
Python Bindings : ON
The not very friendly tutorial and the installation without a GUI have caused me many troubles, that's why I'm writing this log hopefully to save others some time, maybe days.
Installation steps:
- Download the latest version of ns-3 here: Releases.
Note: I've tried the download step both with Bake and with the package. It's definitely easier and faster using the package, the tutorial is also more compatible with it. 2.
$ cd [PATH-to-your-ns3.36]
$ ./build.py --enable-examples --enable-tests **wait for it**
$ cd ns-3.36
$ ./ns3 configure --enable-sudo --enable-examples --enable-tests --enable-python-bindings --build-profile=debug **wait for it**
$ ./ns3 build **wait for it**
$ ./ns3 run hello-simulator
Hello Simulator
If you see this last line, it means your build of ns-3.36 is successful. Then try:
$ ./ns3 install **I think this helps, but I don't know why, tutorial didn't mention it**
$ ./ns3 run --no-build examples/tutorial/first.py -v
At time +2s client sent 1024 bytes to 10.1.1.2 port 9
At time +2.00369s server received 1024 bytes from 10.1.1.1 port 49153
At time +2.00369s server sent 1024 bytes to 10.1.1.1 port 49153
At time +2.00737s client received 1024 bytes from 10.1.1.2 port 9
Finished executing the following commands:
cd .; export PATH=$PATH:/Users/Dora/Downloads/ns-allinone-3.36/ns-3.36/build/lib PYTHONPATH=/Users/Dora/Downloads/ns-allinone-3.36/ns-3.36/build/bindings/python LD_LIBRARY_PATH=/Users/Dora/Downloads/ns-allinone-3.36/ns-3.36/build/lib ; python3 /Users/Dora/Downloads/ns-allinone-3.36/ns-3.36/examples/tutorial/first.py
If you see this kind of results, it means your Python bindings are also successfully generated automatically.
If not, problems can be (as far as I encountered):
The Python version is not a match to your build: I used 3.8.10, it's the latest version of Python 3.8 that comes with an installer. The tutorial mentioned that Python3.6-3.8 can support API scanning fine.
Also make sure all the dependencies for Python are under the same path. Or alter the path to Python dependencies using some instructions. "For Python bindings, the important prerequisites are clang-dev, cmake, cxxfilt, llvm-dev, python3-dev, and python3-setuptools." reference
Some errors and fixes:
Fatal Python error: _PyInterpreterState_Get(): no current thread state
**this means runtime is using the wrong python, not the one build used**
$ whereis python3
python3: /usr/bin/python3 /Library/Frameworks/Python.framework/Versions/3.8/share/man/man1/python3.1
**Build uses the first path by default**
$ echo $PATH
/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/Dora/Library/Python/3.8/bin:/Applications/Wireshark.app/Contents/MacOS
$ export PATH=/usr/bin:/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/Dora/Library/Python/3.8/bin:/Applications/Wireshark.app/Contents/MacOS
**put path found above "/usr/bin" before all others**
Now I want to import ns packages into my PyCharm.
- The generated Python bindings are here to find: ./build/bindings/python, I have two folders here: ns and visualizer.
ls ./build/bindings/python ns visualizer
- Copy python binding folders to either the project root directory or the Python path that you found above (inside site-packages).
- Open Pycharm (or your IDE), go to Pycharm->Preferences->Project: pythonProject->Python Interpreter, change your Python interpreter to the one you found above (Yes, I did that...).
- I copied the examples/tutorial/first.py file into my IDE. It still shows errors associated with import, but I can run it just fine.
Try this to check PyViz functions:
./ns3 run --no-build src/flow-monitor/examples/wifi-olsr-flowmon.py --vis -v
There are definitely other solutions, this in only how I've done it without the need to find too many instructions/fixes online.