1

Literally yesterday all my colab notebooks using graph-tool library were working correctly. All I needed to do was to add the following lines at the beginning:

!echo "deb http://downloads.skewed.de/apt bionic main" >> /etc/apt/sources.list;
!apt-key adv --keyserver keys.openpgp.org --recv-key 612DEFB798507F25;
!apt-get update;
!apt-get install python3-graph-tool python3-cairo python3-matplotlib;
!pip install ipympl;

then I would write from graph_tool.all import * and everything was fine. These instructions are according to this official notebook https://colab.research.google.com/github/count0/colab-gt/blob/master/colab-gt.ipynb.

However today this workflow does not work anymore. The installation commands go smoothly but when importing the module from graph_tool.all import * I get ModuleNotFoundError: No module named 'graph_tool'. I have tried adding the commands proposed in Trouble installing graph-tool package on google colab but it gave me the same outcome.

I have read that this may happen due to graph-tool dependencies on python 3.6 and now Colab has 3.7 therefore I tried creating an anaconda environment with Python 3.6 in my colab notebook using:

!wget -c https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
!chmod +x Miniconda3-4.5.4-Linux-x86_64.sh
!bash ./Miniconda3-4.5.4-Linux-x86_64.sh -b -f -p /usr/local
!conda install -q -y --prefix /usr/local python=3.6 ujson
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')

then I wrote this line (I think it somehow binds anaconda with my notebook but I am not sure):

!conda install -c conda-forge ipython jupyter

Finally I performed the installation using the command (modifying the instructions from the documentation on installation https://git.skewed.de/count0/graph-tool/-/wikis/installation-instructions):

!conda install -c conda-forge graph-tool

After this I can import the module. But my problem is that all these installations ARE REALLY SLOW. It can take up an hour until I install graph-tool mostly because anaconda is solving environments really long.

Does anyone have a smarter idea for the graph-tool installation in Colab? I should add that I cannot resign from doing my analysis in the cloud (I want to easily share my notebook and make possible online running for everyone). Maybe some other interactive python notebooks exist that have the possibility of installing graph-tool?

Grateful in advance for your help.

1 Answers1

2

Try Mamba

Here's a Colab notebook that uses Mamba to install it.

In summary, it

  • installs Miniconda Python 3.71
  • installs Mamba (the fast version of Conda)
  • installs graph-tool
  • adjusts for some dynamic library nuisances

Important: The GLIBC used by graph-tool is newer than the system version in the Colab Runtimes. Unfortunately, since libstdc++.so is loaded when the runtime launches, simply adding the Conda one to LD_LIBRARY_PATH is not sufficient (i.e., system one is cached). The notebook adjusts for this by adjusting the symlink of libstdc++.so.6 to point to the Conda one. However, one has to restart the Runtime after this. After that, continue running the subsequent cells (i.e., you should not rerun any of the setup).


[1] Colaboratory currently runs Python 3.7, not Python 3.6 which could be one of the issues with OP approach.

merv
  • 67,214
  • 13
  • 180
  • 245