0
votes

I have been struggling quite some time with this now, and I think I narrowed down the cause of the following problem:

Using a virtual python 3.8 environment in Spyder through Anaconda, I was able to plot everything I wanted; extensive and complex plots using a palatino latex font. However, as soon as I enter the least bit of gmsh code into it, errors pop up like 'latex could not be found' or 'missing font metrics file' or 'dvipng not found'. I can only guess that gmsh messes up with the directories, but sys.path revealed that all relevant folders (for executables Miktex, dvipng) are still there. I am fairly new to python, so I hope that you guys notice some very stupid or basic mistake I made. Thanks in advance!

The minimal example that causes the issue for me:

import gmsh, numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True) # usetex=False resolves the issue, but I NEED this font haha

if False: # If set to True, the errors will occur.
    gmsh.initialize()
    gmsh.finalize()

Y = np.random.random(15) + 2*np.random.rand(1)
plt.plot(Y)
plt.title(r'$\Sigma_1^2 \mathrm{somehillsboye}$')

P.S. The virtual environment is set-up like this:

In order to avoid dependency clashes due to different python versions, this project uses python 3.8. Activate it with Anaconda using the following steps:

  1. Launch the Anaconda Navigator application.
  2. Within this application, launch the CMD.exe prompt.
  3. Within this prompt, separately execute the following lines for python 3.8 and necesary modules (pressing "y" after each "install or create): conda create --name py38 python=3.8

conda activate py38

conda install --name py38 spyder -c conda-forge

conda config --add channels conda-forge

conda install libspatialindex==1.9.3 rtree==0.9.7

conda install numpy==1.21.2 scipy==1.6.2 matplotlib==3.4.2

conda install gmsh python-gmsh

conda install -c conda-forge/label/cf202003 miktex

conda install ghostscript

spyder

1
P.S., the virtual environment is set-up like this:Casper Spook

1 Answers

0
votes

I solved it!

The issue seems more general than I thought and I found an anwer here: https://gitlab.onelab.info/gmsh/gmsh/-/issues/1142

It turns out that gmsh.initialize() messes with the PATH and PYTHONPATH environment, potentially obscuring the directory of executables (like miktex for instance). To prevent the issue, simply change:

gmsh.initialize()

to

gmsh.initialize(['-noenv'])