# Problem with installation of latest gmsh 4.6.0 via pip

**URL:** <https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078>\
**Category:** installation\
**Created:** [September 11, 2020, 9:56am UTC](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078 "2020-09-11T09:56:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nexius](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@Nexius](https://fenicsproject.discourse.group/u/Nexius)\
**Post date:** [September 11, 2020, 9:56am UTC](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078/1 "2020-09-11T09:56:19Z")

</div>

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](https://fenicsproject.discourse.group/t/neumann-condition-does-not-work-after-cutting-the-domain/3651/4)).

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! 🤣 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.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 11, 2020, 11:09am UTC](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078/2 "2020-09-11T11:09:01Z")

</div>

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

```auto
 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](https://github.com/FEniCS/dolfinx/blob/master/docker/Dockerfile)

```auto
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.

---

<div class="post-metadata">

**Author:** ![Nexius](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@Nexius](https://fenicsproject.discourse.group/u/Nexius)\
**Post date:** [September 11, 2020, 12:42pm UTC](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078/3 "2020-09-11T12:42:48Z")

</div>

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. 🤩

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
```

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 11, 2020, 12:57pm UTC](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078/4 "2020-09-11T12:57:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gdmcbain](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/gdmcbain/32/256_2.png) [@gdmcbain](https://fenicsproject.discourse.group/u/gdmcbain)\
**Post date:** [September 14, 2020, 11:55pm UTC](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078/5 "2020-09-14T23:55:49Z")

</div>

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

```auto
pip install gmsh-sdk

```

I haven’t tried it in a container.
