Problem with installation of latest gmsh 4.6.0 via pip

Dear all.

Already for some time, I use FEniCS in a docker environment + gmsh + pygmsh + meshio. Here are the specifications of my system:

  • Lubuntu 18.04
  • FEniCS docker version 2019.1.0

Inside the FEniCS container, I installed the packages as follows:

sudo apt update ; sudo apt dist-upgrade
sudo apt install gmsh python3-h5py python3-lxml python-h5py python-lxml python3-pip
sudo pip install --upgrade pip
sudo -H pip install pygmsh meshio
sudo -H pip3 install pygmsh meshio

Everything works very well, I can use pygmsh and OpenCASCADE without any problem (see, e.g., here: Link).

However, the point is that gmsh is installed from the Ubuntu 18.04 repositories. The version of gmsh is quite old, it is version 3.0.6, and I would like to profit now from the latest version 4.6.0.

One way is to compile gmsh inside the container, which simply is a mess! :rofl: The second way is to use pip instead of using apt:

sudo -H pip gmsh
sudo -H pip3 gmsh

This is what I have done: a clean install of gmsh in a new FEniCS container. However, when I type gmsh, it says:

Traceback (most recent call last):
  File "/usr/local/bin/gmsh", line 6, in <module>
    import gmsh
ModuleNotFoundError: No module named 'gmsh'

After the pip install, gmsh is located in

/usr/local/lib/python3.6/dist-packages/

… but there is only the directory gmsh-4.6.0.dist-info, which only contains some info.

Questions: Did I oversee some important step? Has one of you installed a relatively new gmsh version in the FEniCS docker environment? Thanks in advance for some help.

This is not a dolfin issue, but an issue with how you install gmsh.
I’ve reproduced this with the following minimal example:

 docker run -ti -v $(pwd):/home/shared -w /home/shared --rm --shm-size=512m ubuntu:18.04
apt update
apt install python3-pip -y
pip3 install gmsh
pip3 list
python3 -c "import gmsh"

As gmsh is not a python package (the gmsh interface is just an add-on to the actual gmsh package.
Consider the following installation processes (adapted from dolfinx’s Dockerfile

docker run -ti -v $(pwd):/home/shared -w /home/shared --rm --shm-size=512m ubuntu:18.04
apt update
apt install python3-pip -y
apt-get install wget libglu1 libxrender1  libxcursor-dev libxft-dev libxinerama-dev -y
cd /usr/local 
wget -nc  http://gmsh.info/bin/Linux/gmsh-4.6.0-Linux64-sdk.tgz
tar -xf gmsh-4.6.0-Linux64-sdk.tgz 
rm gmsh-4.6.0-Linux64-sdk.tgz
export PYTHONPATH=/usr/local/gmsh-4.6.0-Linux64-sdk/lib:$PYTHONPATH
export PATH=/usr/local/gmsh-4.6.0-Linux64-sdk/bin:$PATH
cd /home/shared
python3 -c "import gmsh"

These commands should run nicely in the fenics container as well.

1 Like

Hi dokken.

It works, thanks a lot!

So, one has to hack directly the Ubuntu system, that is: one manually installs gmsh into /usr/local by downloading the latest version and extracting it into the latter directory. Then one sets 2 path variables and that’s it. :star_struck:

I’m still wondering why it doesn’t work with pip. Anyway …

Here is a small script which installs everything inside the container (could be useful). Just save this script as, e.g., Install.sh and execute it by sh ./Install.sh inside the container in the directory ~/shared (the script should be placed inside the directory of the host system where the container has been started before).

# Update the Ubuntu system.
sudo apt update
sudo apt dist-upgrade -y
# Install h5py, lxml and python3-pip.
sudo apt install -y python3-h5py python3-lxml python-h5py python-lxml python3-pip
# Update pip.
sudo pip install --upgrade pip
# Install pygmsh and meshio.
sudo -H pip  install pygmsh meshio
sudo -H pip3 install pygmsh meshio
# Install gmsh, latest version
sudo apt-get install -y wget libglu1 libxrender1  libxcursor-dev libxft-dev libxinerama-dev -y
cd /usr/local
sudo wget -nc  http://gmsh.info/bin/Linux/gmsh-4.6.0-Linux64-sdk.tgz
sudo tar -xf gmsh-4.6.0-Linux64-sdk.tgz
sudo rm gmsh-4.6.0-Linux64-sdk.tgz
cd
# Set variables.
echo "export PYTHONPATH=/usr/local/gmsh-4.6.0-Linux64-sdk/lib:$PYTHONPATH" >> .profile
echo "export PATH=/usr/local/gmsh-4.6.0-Linux64-sdk/bin:$PATH" >> .profile
echo "export PYTHONPATH=/usr/local/gmsh-4.6.0-Linux64-sdk/lib:$PYTHONPATH" >> .bashrc
echo "export PATH=/usr/local/gmsh-4.6.0-Linux64-sdk/bin:$PATH" >> .bashrc
# Replace 'webagg' with 'tkagg'.
sed -i 's/backend: webagg/backend: tkagg/g' .config/matplotlib/matplotlibrc
# Then, make some alias commands.
echo "alias dir='ls -al'" >> .bash_aliases

That is a question you could ask the Gmsh developers. The minimal example showing it fail on a clean ubuntu 18.04 image should be supplied then.

An alternative that I use is (Ubuntu 20.04.1 LTS, python 3.7.9 from Miniconda3, fenics 2019.1.0 from conda-forge)

pip install gmsh-sdk

I haven’t tried it in a container.

2 Likes