Skip to content
Search

NetworKit

lastmod 2025-02-14created 2021-03-296 edits

NetworKit is a growing open-source toolkit for high-performance network analysis. Its aim is to provide tools for the analysis of large networks in the size range from thousands to billions of edges. For this purpose, it implements efficient graph algorithms, many of them parallel to utilize multicore architectures. These are meant to compute standard measures of network analysis, such as degree sequences, clustering coefficients, and centrality. In this respect, NetworKit is comparable to packages such as NetworkX, albeit with a focus on parallelism and scalability. NetworKit is also a testbed for algorithm engineering and contains several novel algorithms from recently published research, especially in the area of community detection.

NetworKit is a Python module. Performance-aware algorithms are written in C++ (often using OpenMP for shared-memory parallelism) and exposed to Python via the Cython toolchain. Python in turn provides a rich environment of tools for data analysis and the ability to work interactively. The core of NetworKit can also be built and used as a native library.

Creating a Graph directly

import networkit as nk

G = nk.Graph(5, False, True)
print(G.numberOfNodes(), G.numberOfEdges())
print(G.isWeighted(), G.isDirected())

G.addEdge(1, 3)
G.addEdge(2, 4)
G.addEdge(1, 2)
G.addEdge(3, 4)
G.addEdge(2, 3)
G.addEdge(4, 0)
G.addNode()
G.addEdge(0, 5)
nk.overview(G)

for u in G.iterNodes():
    print(u)

Troubleshooting

pyenv: ninja: command not found

The following error may be printed during installation.

...
    initializing NetworKit compilation with: 'cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/private/var/folders/6v/598t63jj15lbcn_nq9nm12ww0000gn/T/pip-install-j5ycf86a/networkit_46f7b29978854c278177950b8d4195ae/build/lib.macosx-10.14-x86_64-3.7 -DCMAKE_CXX_COMPILER=c++ -DNETWORKIT_FLATINSTALL=ON -DNETWORKIT_PYTHON=/Users/yourname/.pyenv/versions/3.7.7/Python.framework/Versions/3.7/include/python3.7m -DNETWORKIT_PYTHON_SOABI=cpython-37m-darwin -GNinja /private/var/folders/6v/598t63jj15lbcn_nq9nm12ww0000gn/T/pip-install-j5ycf86a/networkit_46f7b29978854c278177950b8d4195ae'
    CMake Error at CMakeLists.txt:2 (project):
      Running

       '/Users/yourname/.pyenv/shims/ninja' '--version'

      failed with:

       pyenv: ninja: command not found



      The `ninja' command exists in these Python versions:

        3.6.1/envs/opy-yourname-3.6.1
        3.6.8/envs/opy-yourname-3.6.8
        opy-yourname-3.6.1
        opy-yourname-3.6.8



      Note: See 'pyenv help global' for tips on allowing both

            python2 and python3 to be found.



    -- Configuring incomplete, errors occurred!
    See also "/private/var/folders/6v/598t63jj15lbcn_nq9nm12ww0000gn/T/pip-install-j5ycf86a/networkit_46f7b29978854c278177950b8d4195ae/build/build_python/CMakeFiles/CMakeOutput.log".
    cmake returned an error, exiting setup.py
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/yourname/.pyenv/versions/3.7.7/envs/opy-yourname-3.7.7/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6v/598t63jj15lbcn_nq9nm12ww0000gn/T/pip-install-j5ycf86a/networkit_46f7b29978854c278177950b8d4195ae/setup.py'"'"'; __file__='"'"'/private/var/folders/6v/598t63jj15lbcn_nq9nm12ww0000gn/T/pip-install-j5ycf86a/networkit_46f7b29978854c278177950b8d4195ae/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/6v/598t63jj15lbcn_nq9nm12ww0000gn/T/pip-record-r49k1djw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/yourname/.pyenv/versions/3.7.7/envs/opy-yourname-3.7.7/include/site/python3.7/networkit Check the logs for full command output.

Install ninja as follows.

pip install ninja

See also

Favorite site

author Zer0 sitemap