Installation to singularity container

Hi Everyone,

After spending a while trying to get graph-tools to work on a cluster (conda couldn’t find it) I finally got an apptainer/singularity .def file that works, so I thought I’d post it here for reference.

Some parts are probably irrelevant or suboptimal - feel free to comment. I’m not sure why the numpy/scipy version requirements are there, so this might be an older version of graph-tools.

# adapted from https://forum.skewed.de/t/libgraph-tool-core/1535/9

Bootstrap: docker
From: ubuntu:22.04

%post
    apt-get -y update
    apt-get -y dist-upgrade
    apt-get -y install gnupg2
    apt-get -y install ca-certificates
    apt-get -y install software-properties-common
    apt-get -y install wget

    apt-key adv --keyserver hkps://keys.openpgp.org --recv-key 612DEFB798507F25 
    add-apt-repository "deb https://downloads.skewed.de/apt/ `echo ubuntu:jammy | sed s/[^:]*://` main"

    apt-get update

    apt-get install -y python3-pip    
    apt-get -y install python3-graph-tool

    pip3 install numpy==1.22.4 scipy==1.8.1 matplotlib==3.8.0 contourpy==1.2.0

    rm -rf /var/lib/apt/lists/*
    apt-get clean

No need for any of that, the installation instructions already shows how the official image container can be used with singularity (apptainer):

apptainer pull docker://tiagopeixoto/graph-tool

Also, the name of the library is graph-tool, not graph-tools…

1 Like

Oh, okay. Thank you, Tiago.

I’m new to containers and wanted to add more packages beyond graph-tool.

I’m not sure how to add things to tiagopeixoto/graph-tool, but this worked well:

Bootstrap: docker
From: pbaumgartner/graph-tool-pip

%post
    pip install --upgrade pip
    pip install xgboost

FWIW, some time ago I was also experiencing the same problem: it is hard to add more packages beyond graph-tool to the tiagopeixoto/graph-tool image. I finally had to do RUN pip install --break-system-packages uvicorn fastapi in my dockerfile. It doesn’t look nice. If there is a better way to do that, or if pbaumgartner/graph-tool-pip is the right image to build from in such a context, it would be useful to add the information to the installation instructions.

Adding packages to any a docker image is straightforward in the majority of cases; you just need to write a Dockerfile and set the original image as FROM, and just install whatever package you want.

For example:

FROM tiagopeixoto/graph-tool

RUN pacman -S python-basemap --noconfirm --needed

will install basemap on top of the standard graph-tool image.

I’ll add this to the installation instructions.

Well I’m not an arch user so I cannot say what’s an easy way to install a
python package, like fastapi, for instance. I do know though that pacman
does not install python packages, so I first installed pip (with pacman),
but could not install python packages without using the
–break-system-packages, as mentioned above, which does not really seem
like a good thing to do.

Of course pacman installs python packages. I just gave you an example of how to install basemap, a python package, using pacman. Believe your own eyes!

You can also install graph-tool via pacman.

You can also install via pip, if the package is not available in pacman, or via AUR. That scary message can be ignored as long as you don’t overwrite with pip a package that has been installed with pacman. But since you’re inside a docker image, nothing really serious can happen at all.

You can also install via pip --user which will not overwrite the system path at all, and hence there will be no danger of interfering with pacman.

Well, I decided to give it a try and believe my own eyes… I gather that I
should just prefix the package name with python- and go ahead. It does
work with fastapi, but not with uvicorn:

image.png

I imagine that’s why you said “You can also install via pip, if the package
is not available in pacman, or via AUR”. I don’t know what’s AUR, but
installing with pip, at least as I’d do it, fails:

At which point we’re back to the --break-system-packages option. I know
that being within a container nothing serious can happen and in fact that’s
the way I’m proceeding, but I certainly would prefer having a more robust
recipe for building images. I, for one, wouldn’t know how to check whether
something was broken or not, other than extensive testing…

There’s no point in continuing this discussion here. There’s a whole internet out there teaching you how to use pacman, how to find packages (instead of guessing what they are named), what AUR is and how to use it. If you’re unwilling to spend the effort, there’s nothing more I can do for you.

You’re right, specially considering that this forum is for graph-tool, not arch. I was just sharing my suboptimal experience using the arch-based image with the intent of helping you help non-arch users like me. I did solve my issue using the internet, long before deciding to chime into this thread (which just made me remember about it).

I just don’t get how anyone can consider this difficult. Here’s the package you are searching for. I used google to find it: https://archlinux.org/packages/extra/any/uvicorn/. It’s not more difficult to find packages for Arch than for any other system. If this is suboptimal, how would optimal look like?

I’m not saying that it was difficult, but writing a working dockerfile was more time-consuming than I would have liked it to be. Those are just tools for me, not my main area of expertise; there’s nothing wrong in wanting them to be “ergonomic”, to put it that way… In the link that you provided I see no installation instructions. I’m sure I can (“easily”, sort of) dig in and figure things out, but that would certainly not be the best way for me to invest my time at this moment. So I’ll stick to the --break-system-packages solution. For the record, at the time I was writing the dockerfile I did try to follow the pip error message hints (those about the externally managed environment), ie prefixing with python-, using pipx and also switching to a venv environment. I just couldn’t make any of those approaches work within a reasonable time-frame, so gave up and accepted the potentially broken system.

It’s amazing. I just explained how to install it via pacman. You do:

pacman -S uvicorn

Look, this stuff is completely trivial. It can’t get much easier.

I’m closing this thread, since it’s quite pointless at this point.