How to install graph-tool on macOS

Introduction

This article summarizes how to install the network analysis library graph-tool. This library is similar to networkx and is a library that implements functions for manipulating graph data and calculating network features from python.

While networkx is implemented in pure python, graph-tool is implemented in C ++ using OpenMP, so the calculation is very fast, which is an advantage over networkx. On the other hand, it cannot be installed by simply pip install like the pure python library, and it depends on many libraries including new C ++ specifications and GUI libraries, so it is very difficult to build manually. difficult.

As of 2020.10.1, the latest version 2.35 can be installed with a package management tool, which makes the installation much easier. Here is a summary of the steps to install on macOS.

Prerequisites

I usually use pyenv and pipenv for python version control and package management, so I'll show you how to use them as much as possible.

Various installation methods

The installation method is summarized on this page. https://git.skewed.de/count0/graph-tool/-/wikis/installation-instructions

Roughly speaking, there are the following methods.

--How to use docker --How to use anaconda --How to install on your system with homebrew --Manual build

After trying various things, each has advantages and disadvantages, but the method using ** conda seems to be the easiest and most practical **. (In the first place, I personally don't like conda and manage the virtual environment with pipenv, but it was still easy to use conda)

Here, the installation method is described about how to use docker and how to use conda.

How to use docker

--Advantage: The easiest to use --Disadvantage: It's hard to put in additional packages

First, download the image. In addition to graph-tool, numpy and jupyter are already installed in this docker image.

$ docker pull tiagopeixoto/graph-tool

To start it, execute the following command.

$ docker run -p 8888:8888 -p 6006:6006 -it -u user -w /home/user tiagopeixoto/graph-tool bash
$ jupyter notebook --ip 0.0.0.0

Now you can use jupyter by accessing http: // localhost: 8888 browser.

When you're done, press Ctrl-C to quit jupyter and quit the shell. Since the container itself remains even after exiting, you can restart the container with docker start <container>, and more

$ docker exec -it -u user <container> jupyter notebook --ip 0.0.0.0

You can restart jupyter in the same way with.

In actual operation, it is often easier to mount the directory at hand as follows.

$ docker run -p 8888:8888 -p 6006:6006 -it -u user -w /home/user -v $(pwd):/home/user tiagopeixoto/graph-tool bash

This method is good until you first start using it, but it gets harder if you try to customize it a bit. I tried to add an additional package with pip, but I couldn't use the pip command in this image. I tried to install jupyter's nb extensions, but I didn't know how to install it.

How to use conda

--Advantage: Easy to introduce other packages with conda --Disadvantage: Cannot be unified when using other tools such as pipenv

Here, install anaconda using pyenv.

$ pyenv install anaconda3-2020.02
$ pyenv local anaconda3-2020.02         #Use the anaconda you just installed below

Then install the graph-tool (and other) packages with the conda command.

$ conda create --name gt -c conda-forge graph-tool          # `gt`Build a virtual environment named conda-from forge graph-install tool
$ conda install -n gt -c conda-forge ipython jupyter           #Do this when installing additional packages

As a caveat here, be sure to add -c conda-forge to specify that you want to install the package from conda-forge. Also, it is good to specify -c conda-forge when installing additional packages as well as graph-tool. It seems that the default Anaconda official package and graph-tool often conflict.

The usual way to use the built virtual environment gt is to conda activate, but to use the conda activate command, edit ~ / .zshrc. There is a need. I don't want to change the existing environment so much, so I decided to use pyenv to switch the environment as follows. When you execute pyenv versions, you can see that the virtual environment created earlier is created with the name ʻanaconda3-2020.02 / envs / gt. Therefore, switch this environment with a command such as pyenv local`.

$ pyenv local anaconda3-2020.02/envs/gt

test

As a test, let's run the following test code.

hello.py


import graph_tool.all as gt

g = gt.Graph()
v1 = g.add_vertex()
v2 = g.add_vertex()

e = g.add_edge(v1, v2)
gt.graph_draw(g, vertex_text=g.vertex_index, output="two-nodes.pdf")
$ python hello.py

Success if the following image file is created with the name "two-nodes.pdf" after execution.

image.png

Recommended Posts

How to install graph-tool on macOS
How to install cx_Oracle on macOS Sierra
How to install VMware-Tools on Linux
How to install pycrypto on Windows
How to install OpenCV on Mac
How to install PyPy on CentOS
How to install TensorFlow on CentOS 7
How to install Maven on CentOS
How to install Go on Ubuntu
How to install music 21 on windows
How to install aws-session-manager-plugin on Manajro Linux
How to install drobertadams / toggl-cli on Mac
[Kivy] How to install Kivy on Windows [Python]
How to install packages on Alpine Linux
How to install Anisble on Amazon Linux 2
How to install richzhang / colorization on Windows 10
How to install Apache (httpd) on CentOS7
How to install php7.4 on Linux (Ubuntu)
How to install Eclipse GlassFish 5.1.0 on CentOS 7
How to install Apache (httpd) on CentOS8
How to install NumPy on Raspberry Pi
How to install Python
How to install pip
How to install archlinux
How to install python
How to install BayesOpt
How to install Nbextensions
How to install Prover9
[2020 version] How to install Python3 on AWS EC2
How to install OpenCV on Jetson Nano Python
How to quickly install h5py on Windows 10 [Unofficial]
How to install OpenGM on OSX with macports
How to install Camunda Modeler on Manjaro Linux
[Python] How to install OpenCV on Anaconda [Windows]
How to install / verify graphviz on anaconda / windows10
[2020.8 latest] How to install Python
How to install Python [Windows]
Tabpy 1.0 (2020-01 version) How to install
How to register on pypi
How to install mkl numpy
How to install Pelican blog
How to install Git GUI and Gitk on CentOS
How to install caffe on OS X with macports
[AWS EC2] How to install Maven on Amazon Linux 2
How to install git on Linux such as EC2
How to install python using anaconda
Steps to install MySQL 8.0 on CentOS 8.1
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to install and use Tesseract-OCR
How to use Dataiku on Windows
Steps to install matplotlib on Mac
Notes on how to use pywinauto
How to install python-pip with ubuntu20.04LTS
How to install wkhtmltopdf (Amazon Linux2)
How to deploy django-compressor on Windows
Notes on how to use featuretools
How to run matplotlib on heroku
How to install MBDyn (Linux Ubuntu)
How to use homebrew on Debian
Misunderstanding on how to connect cnn
How to install and configure blackbird