Aaron's Blog

https://aaronchenwei.github.io/

View on GitHub
31 May 2023

Build SNAP with Python 3.10 on Ubuntu 22.04 LTS

by aaronchenwei

Stanford Network Analysis Platform (SNAP) is a general purpose network analysis and graph mining library. It is written in C++ and easily scales to massive networks with hundreds of millions of nodes, and billions of edges. It efficiently manipulates large graphs, calculates structural properties, generates regular and random graphs, and supports attributes on nodes and edges.

Snap.py is a Python interface for SNAP. It provides performance benefits of SNAP, combined with flexibility of Python. Most of the SNAP C++ functionality is available via Snap.py in Python.

SNAP 6.0 was release on December 2020. There is on wheel files for python 3.10 or 3.11 in pypi site. This blog describes the steps to build SNAP with Python 3.10 on Ubuntu 22.04 LTS.

1. Launch Ubuntu 22.04 Container

version: "2"

services:
  ubuntu:
    build:
      context: .
      dockerfile: Dockerfile
    image: aaronchenwei/ubuntu-jammy
    container_name: ubuntu-jammy
    network_mode: host
    tty: true
    stdin_open: true
    environment:
      - TZ=Asia/Shanghai
FROM docker.io/ubuntu:jammy

USER root
WORKDIR /root

RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list \
    && sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list \
    && apt-get update \
    && apt-get upgrade -y \
    && apt-get install -y ca-certificates \
    && sed -i 's/http:/https:/g' /etc/apt/sources.list

RUN apt-get install -y vim wget build-essential git python3 python3-pip
$ docker compose build
$ docker compose exec ubuntu bash -l

We are using user root inside container.

2. Git clone source code

# git clone https://github.com/snap-stanford/snap-python.git
# git clone https://github.com/snap-stanford/snap

3. Install SWIG

# apt install swig

4. Build Wheel

# cd snap-pyton

After line 49 add include path for python 3.10

IFLAGS3 += -I/usr/local/include/python3.10  -I/usr/include/python3.10
# cd swig
# make clean-obj
# time make whldist3

After building, we can find wheel file snap_stanford-6.0.0-cp310-cp310-manylinux1_x86_64.whl under directory dist.

4. Test wheel

$ pip3 install snap_stanford-6.0.0-cp310-cp310-manylinux1_x86_64.whl