Skip to content

Installation

net-bench (and also networkx and matplotlib) should be installed into the environment with your preferred method.

net-bench

Create a directory (also in Git if you want to). Run the following in your terminal:

pip install --user net-bench

Note

If you want to use a virtual environment: Now is the time to do so.

Updates

To update the package (e.g. if a new update has been released):

pip install --upgrade --user dsslab-net-bench

Usage

After writing a script (e.g. one called main.py) it can be run via the terminal:

python main.py
By running this command, the previously installed dependencies are automatically provided for the script.

Optional: Graphviz for Layouting

Graphviz, an external tool for the visualisation of figures, makes it possible to have nicer layouting, especially in heavily connected graphs.

If you want to use Graphviz for layouting:

Warning

Before executing the following command, please read the_paragraph_further_down.

pip install --user dsslab-net-bench[graphviz]
This way, the optional integration of Graphviz is installed.

graphviz

The installation of graphviz is a bit more difficult and depends on your operating system. Graphviz is a program for visualizing all manner of graphs, while pygraphviz is a python package, which makes it possible to use Graphviz while using python. That's why pygraphviz can be installed using pip. Graphviz has to be installed on the level of the operating system.

The installation manual for pygraphviz (thats the accompanying python package) is very useful: https://pygraphviz.github.io/documentation/stable/install.html

A few suggestions for the installation of graphviz:

Windows

  • Chocolatey:
    PS C:\> choco install graphviz
    PS C:\> python -m pip install --config-settings="--global-option=build_ext" `
                  --config-settings="--global-option="-IC:\Program Files\Graphviz\include" `
                  --config-settings="--global-option="-LC:\Program Files\Graphviz\lib" `
                  pygraphviz
    
    pygraphviz has to be installed afterwards with the reference to Graphviz.

Warning

In this case, pygraphviz must not be installed via pip!

macOS

Also see the pygraphviz installation guides.

  • Homebrew:
    brew install graphviz
    

Note

In this case, pip can be used for installing pygraphviz:

pip install dsslab-net-bench[graphviz]

  • MacPorts
    port install graphviz
    

Warning

In this case, pip cannot be used for the installation of pygraphviz. pygraphviz must be installed manually:

pip install --config-settings="--global-option=build_ext" \
          --config-settings="--global-option=-I/opt/local/include/" \
          --config-settings="--global-option=-L/opt/local/lib/" \

Linux

You probably know what your doing. Use the package manager of your choice for the installation.

Note

Graphviz is made up of two packages, e.g. graphviz and graphviz-dev for Ubuntu. Please consider this beforehand for your package management.

Afterwards you can use the default installation via pip.

Nix (just for experts)

The repo includes a Nix Flake, which provides a development environment and automatically installs Graphviz:

{
  description = "dsslab-net-bench flake for environment handling";

  inputs = {
    systems.url = "github:nix-systems/default";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    devenv.url = "github:cachix/devenv";
  };

  outputs = { self, nixpkgs, devenv, systems }@inputs:
    let
      forEachSystem = nixpkgs.lib.genAttrs (import systems);
    in
      {
        packages = forEachSystem (system: {
          devenv-up = self.devShells.${system}.default.config.procfileScript;
        });
        devShells = forEachSystem (system:
          let
            pkgs = nixpkgs.legacyPackages.${system};
          in
            {
              default = devenv.lib.mkShell {
                inherit inputs pkgs;
                modules = [
                  {
                    packages = [
                      pkgs.graphviz
                      pkgs.python312Packages.pygraphviz
                      pkgs.gcc
                    ];
                    languages.python = {
                      enable = true;
                      package = pkgs.python312;
                      poetry = {
                        activate.enable = true;
                        enable = true;
                        install.enable = true;
                        install.allExtras = true;
                        install.groups = [ "dev" ];
                      };
                    };
                  }
                ];
              };
              python313 = devenv.lib.mkShell {
                inherit inputs pkgs;
                modules = [
                  {
                    packages = [
                      pkgs.graphviz
                      # pkgs.python39Packages.pygraphviz
                      pkgs.gcc
                    ];
                    languages.python = {
                      enable = true;
                      package = pkgs.python313;
                      poetry = {
                        activate.enable = true;
                        enable = true;
                        install.enable = true;
                        install.allExtras = true;
                        install.groups = [ "dev" ];
                      };
                    };
                  }
                ];
              };
              python311 = devenv.lib.mkShell {
                inherit inputs pkgs;
                modules = [
                  {
                    packages = [
                      pkgs.graphviz
                      pkgs.gcc
                    ];
                    languages.python = {
                      enable = true;
                      package = pkgs.python311;
                      poetry = {
                        activate.enable = true;
                        enable = true;
                        install.enable = true;
                        install.allExtras = true;
                        install.groups = [ "dev" ];
                      };
                    };
                  }
                ];
              };
              python310 = devenv.lib.mkShell {
                inherit inputs pkgs;
                modules = [
                  {
                    packages = [
                      pkgs.graphviz
                      pkgs.gcc
                    ];
                    languages.python = {
                      enable = true;
                      package = pkgs.python310;
                      poetry = {
                        activate.enable = true;
                        enable = true;
                        install.enable = true;
                        install.allExtras = true;
                        install.groups = [ "dev" ];
                      };
                    };
                  }
                ];
              };
              python39 = devenv.lib.mkShell {
                inherit inputs pkgs;
                modules = [
                  {
                    packages = [
                      pkgs.graphviz
                      # pkgs.python39Packages.pygraphviz
                      pkgs.gcc
                    ];
                    languages.python = {
                      enable = true;
                      package = pkgs.python39;
                      poetry = {
                        activate.enable = true;
                        enable = true;
                        install.enable = true;
                        install.allExtras = true;
                        install.groups = [ "dev" ];
                      };
                    };
                  }
                ];
              };
            });
        templates = rec {
            default = {
                path = ./templates/pythonScript;
                description = "Default setup with dsslab-net-bench and Graphviz.";
            };
        };
      };
}
This file can also be created in your own repo.