How to enable Pyviz on MacOs

1,129 views
Skip to first unread message

Xinhao Dai

unread,
Sep 28, 2022, 6:24:14 PM9/28/22
to ns-3-users
Hello,

I am currently working on ns3.36 on my MacBook. I want to enable the visualization function. However, although I try to install the dependency of PyViz according to https://www.nsnam.org/wiki/PyViz, It still shows me that PyViz lacks dependency. 

As you can see, pygtk, pygoocanvas, pygraphviz with python2.7 are really ancient and It's hard for me to download and install the package in one line. I need to find the source code and build it myself.

Therefore, I want to ask if there is one way for me to to figure out what specific package goes wrong or is missing so I can narrow down my work.

Thanks for any reply and your time!

Li, Ye

unread,
Sep 28, 2022, 7:28:30 PM9/28/22
to ns-3-...@googlegroups.com
Did you try homebrew to install the dependencies?

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/c02954e7-b03b-400d-a260-2a27875b500en%40googlegroups.com.
--
LI, Ye
School of Information Science and Technology
Nantong University
Nantong 226019, Jiangsu Province, China

Xinhao Dai

unread,
Sep 28, 2022, 7:30:56 PM9/28/22
to ns-3-users
No, I use Macports. I can not find the right packages on homebrew.

Tom Henderson

unread,
Sep 28, 2022, 8:03:50 PM9/28/22
to ns-3-...@googlegroups.com
I apologize, that web page (and other macOS installation tips) are badly outdated.  I will try to fix sometime soon.,

There are various issues with installing Python (or multiple Pythons) on macOS, so for this reason, some people use a virtualenv.  I won't get into that option here.

For PyViz, the following packages can be installed using pip3:
pip3 install --user pycairo
pip3 install --user pygobject
pip3 install --user pygraphviz
You probably also want to install 'cairo' via Homebrew or MacPorts.

For ns-3.36 and earlier, pybindgen is needed for Python.  For current ns-3 (and future ns-3.37), cppyy will be needed instead.

- Tom

Xinhao Dai

unread,
Sep 28, 2022, 9:15:17 PM9/28/22
to ns-3-users
Thanks to you reply. I have installed all the packages you mention. However, when I run ./ns3 configure, it still tells me Visualizer requires Python bindings 
and 
PyViz visualizer   : OFF (missing dependency)

-- Using default output directory /Users/Res_proj/Documents/Research/ns-allinone-3.36.1/ns-3.36.1/build

-- Proceeding without cmake-format

-- find_external_library: SQLite3 was found.

-- GTK3 was found.

-- LibXML2 was found.

-- Lib RT is not supported on Mac OS X. Continuing without it.

-- Visualizer requires Python bindings

-- Could NOT find Boost (missing: Boost_INCLUDE_DIR) 

-- GSL was not found. Continuing without it.

-- docs: doxygen documentation not enabled due to missing dependencies: doxygen;dia

-- Failed to locate sphinx-build executable (missing: SPHINX_EXECUTABLE) 

-- docs: sphinx documentation not enabled due to missing dependencies: Sphinx;convert

-- Platform doesn't support TAP and EMU features. Continuing without them.

-- Precompiled headers were enabled

-- Processing src/antenna

-- Processing src/aodv

-- Processing src/applications

-- Processing src/bridge

-- Processing src/brite

-- find_external_library: brite was not found. Missing headers: "Brite.h" and missing libraries: "brite".

-- Skipping src/brite

-- Processing src/buildings

-- Processing src/click

-- find_external_library: click was not found. Missing headers: "simclick.h" and missing libraries: "nsclick;click".

-- Skipping src/click

-- Processing src/config-store

-- Processing src/core

-- Boost Units are an optional feature of length.cc.; Ubuntu ships it within the libboost-dev package.; You may need to clean up the CMake cache after installing it to pass this check.

-- Processing src/csma

-- Processing src/csma-layout

-- Processing src/dsdv

-- Processing src/dsr

-- Processing src/energy

-- Processing src/flow-monitor

-- Processing src/internet

-- Processing src/internet-apps

-- Processing src/lr-wpan

-- Processing src/lte

-- Processing src/mesh

-- Processing src/mobility

-- Processing src/netanim

-- Processing src/network

-- Processing src/nix-vector-routing

-- Processing src/olsr

-- Processing src/openflow

-- find_external_library: openflow was not found. Missing headers: "openflow.h" and missing libraries: "openflow".

-- Skipping src/openflow

-- Processing src/point-to-point

-- Processing src/point-to-point-layout

-- Processing src/propagation

-- Processing src/sixlowpan

-- Processing src/spectrum

-- Processing src/stats

-- Processing src/test

-- Processing src/topology-read

-- Processing src/traci

-- Processing src/traci-applications

-- Processing src/traffic-control

-- Processing src/uan

-- Processing src/virtual-net-device

-- Processing src/wave

-- Processing src/wifi

-- Processing src/wimax

-- ---- Summary of optional ns-3 features:

Build profile                 : default

Build directory               : /Users/Res_proj/Documents/Research/ns-allinone-3.36.1/ns-3.36.1/build

BRITE Integration             : OFF (missing dependency)

DES Metrics event collection  : OFF (not requested)

DPDK NetDevice                : OFF (not requested)

Emulation FdNetDevice         : OFF (not requested)

Examples                      : ON

File descriptor NetDevice     : OFF (missing dependency)

GNU Scientific Library (GSL)  : OFF (missing dependency)

GtkConfigStore                : ON

LibXml2 support               : ON

MPI Support                   : OFF (not requested)

ns-3 Click Integration        : OFF (missing dependency)

ns-3 OpenFlow Integration     : OFF (missing dependency)

Netmap emulation FdNetDevice  : OFF (not requested)

PyViz visualizer              : OFF (missing dependency)

Python API Scanning Support   : OFF (not requested)

Python Bindings               : OFF (not requested)

Real Time Simulator           : OFF (missing dependency)

SQLite support                : ON

Tap Bridge                    : OFF (not requested)

Tap FdNetDevice               : OFF (not requested)

Tests                         : ON



Modules configured to be built:

antenna                   aodv                      applications              

bridge                    buildings                 config-store              

core                      csma                      csma-layout               

dsdv                      dsr                       energy                    

flow-monitor              internet                  internet-apps             

lr-wpan                   lte                       mesh                      

mobility                  netanim                   network                   

nix-vector-routing        olsr                      point-to-point            

point-to-point-layout     propagation               sixlowpan                 

spectrum                  stats                     test                      

topology-read             traci                     traci-applications        

traffic-control           uan                       virtual-net-device        

wave                      wifi                      wimax                     



Modules that cannot be built:

brite                     click                     fd-net-device             

mpi                       openflow                  tap-bridge                

visualizer                



-- Configuring done

-- Generating done

-- Build files have been written to: /Users/Res_proj/Documents/Research/ns-allinone-3.36.1/ns-3.36.1/cmake-cache

Finished executing the following commands:

cd cmake-cache; /Library/Frameworks/Python.framework/Versions/2.7/bin/cmake .. ; cd ..



Joe Pappas

unread,
Mar 23, 2023, 12:31:57 PM3/23/23
to ns-3-users
I am also having trouble getting PyViz to be enabled for my ns-3 (version 3.38) project. 

I use conda and was able to find all of the mentioned packages:
- cppyy
- pycairo
- pygobject
- pygraphviz

But the visualizer is still not enabled. 

I have this other warning during configuration, stating that my python version is incompatible:
-- Python: an incompatible version of Python was found, python bindings will be disabled

-- Visualizer requires Python bindings

I have gotten this same warning in different conda environments on python versions 3.9, 3.10, and 3.11, so not sure which python version I should be using. 

I have tried ns3 versions 3.33 and 3.38. 
I have MacOS version Ventura 13.2.1

Aside:
I have tried doing this without conda, using MacPorts and homebrew (separately), and still have not gotten it to work. 

Any help here would be appreciated.  

Gabriel Ferreira

unread,
Mar 23, 2023, 6:10:11 PM3/23/23
to ns-3-users
The list of compatible python versions currently goes up to 3.9, so it should work. 
3.10, 3.11 and 3.12 will be added in https://gitlab.com/nsnam/ns-3-dev/-/merge_requests/1277

Problem is, this message was printed if the python bindings were not requested. 

Try ./ns3 configure --enable-python-bindings.

Joe Pappas

unread,
Mar 23, 2023, 7:55:14 PM3/23/23
to ns-3-users
That is good to know, thank you for the update! 

That helped and am further along now.

Now I am getting the following warnings:
-- Bindings: python bindings disabled due to the following missing dependencies: cppyy
-- NS3_BINDINGS_INSTALL_DIR was not set. The python bindings won't be installed with ./ns3 install.
-- Set NS3_BINDINGS_INSTALL_DIR="/Users/joe/Library/Python/3.9/lib/python/site-packages" to install it to the default location.

-- Visualizer requires Python bindings

Even though I already installed:
% conda install -c conda-forge cppyy
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

Any suggestions there?

Gabriel Ferreira

unread,
Mar 23, 2023, 9:38:44 PM3/23/23
to ns-3-users
It's picking up the wrong python. Try

. /ns3 configure --enable-python-bindings -- -DPython3_LIBRARY_DIRS=/path/to/conda/libs -DPython3_INCLUDE_DIRS=/path/to/conda/include -DPython3_EXECUTABLE=/path/to/conda/python

You can get these paths by running the following with Python 

import sysconfig
import sys
print(sysconfig.get_config_var('LIBDIR')) 
print(sysconfig.get_config_var('INCLUDEPY')) 
print(sys.executable) 

Joe Pappas

unread,
Mar 24, 2023, 1:10:08 AM3/24/23
to ns-3-users
Okay, thank you! That got me another step further, and the visualizer module is now enabled after configuring. 

I feel I am one more step though. 

After configuring, and then building, I tried to run a file out of my scratch folder (it was the example in src/mobility/examples/main-random-walk.cc, that I just copied to a new file), and I got the error that I've seen before:


But then I noticed that in the configure step, there was another warning still about not setting the NS3 bindings:
-- NS3_BINDINGS_INSTALL_DIR was not set. The visualizer python module won't be installed with ./ns3 install.

I tried just setting an environment variable named this to be the default that they provide, but I'm still getting this warning. 

How do I set this?

Gabriel Ferreira

unread,
Mar 24, 2023, 7:21:50 AM3/24/23
to ns-3-users
This setting iin this warning s meant for packaging and distribution. Just ignore it. 

Joe Pappas

unread,
Mar 24, 2023, 11:12:47 AM3/24/23
to ns-3-users
But I get this error when I try to run the code with the visualizer:

My command:

./ns3 run scratch/drone-mobility/drone --visualize


Error:
```

NS_ASSERT failed, cond="uid != 0", msg="Assert in TypeId::LookupByName: ns3::VisualSimulatorImpl not found", file=/Users/joe/ResearchProjects/ns-allinone-3.38/ns-3.38/src/core/model/type-id.cc, line=843

NS_FATAL, terminating

libc++abi: terminating

Command 'build/scratch/drone-mobility/ns3.38-drone-default --SimulatorImplementationType=ns3::VisualSimulatorImpl' died with <Signals.SIGABRT: 6>.

```


Gabriel Ferreira

unread,
Mar 24, 2023, 11:41:03 AM3/24/23
to ns-3-users
This happens if the visualizer module didn't get built or linked.
It should be in build/lib/libns3.38-visualizer-default.dylib

If it isn't there, it was not built for some reason. 
Typically because Python.h was not found.

Joe Pappas

unread,
Mar 24, 2023, 12:32:05 PM3/24/23
to ns-3-users
It is there and so was built. I thought the scratch folder was supposed to automatically link all of the built modules.

I also see it in the output of the build:
```
[ 67%] Linking CXX shared library /{mydirectory}/ns-allinone-3.38/ns-3.38/build/lib/libns3.38-visualizer-default.dylib
```

Is there something more that I'm supposed to be doing to link it?

Gabriel Ferreira

unread,
Mar 24, 2023, 12:34:42 PM3/24/23
to ns-3-users
It should be linked automatically, but you can check that with `objdump -x your_scratch_executable | grep visualizer-default.dylib`.
Or Apple's otool, but I don't remember the command line. =x

Joe Pappas

unread,
Mar 24, 2023, 1:40:26 PM3/24/23
to ns-3-users
I couldn't get otool to list what I wanted, so I ended up explicitly including the visualizer in my code, and also had to use the trick of adding { PyViz vis } in my main function so that the compiler thinks it's in scope. This got the build to link the visualizer which is good.

I am now getting this error:
```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/joe/ResearchProjects/ns-allinone-3.38/ns-3.38/build/bindings/python/visualizer/__init__.py", line 14, in <module>
    from .core import start, register_plugin, set_bounds, add_initialization_hook
  File "/Users/joe/ResearchProjects/ns-allinone-3.38/ns-3.38/build/bindings/python/visualizer/core.py", line 55, in <module>
    gi.require_version('GooCanvas', '2.0')
  File "/Users/joe/miniconda3/envs/py39/lib/python3.9/site-packages/gi/__init__.py", line 126, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace GooCanvas not available
```

I thought I had all the dependencies installed. But goocanvas is only available with macports and homebrew, not with conda. Am I going to have to figure out how to link these installs with the conda path that I had to specify above?

Gabriel Ferreira

unread,
Mar 24, 2023, 3:08:10 PM3/24/23
to ns-3-users
Hmm, weird. I am going to double check this later, but haven't seen any issues for linking so far.

For GooCanvas, you need to have it within your current python environment/installation.
 If it is not available via conda install, you can still use pip. 
If it also isn't available, try macports (which is the recommended platform for Mac users).

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages