Pb import ngsolve


I encounter an error while execution this command :

from ngsolve import *
Traceback (most recent call last):
File “”, line 1, in
File “/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ngsolve/init.py”, line 13, in
from .ngslib import version, ngstd, bla, la, fem, comp, solve
ImportError: cannot import name ‘fem’ from ‘ngsolve’ (/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ngsolve/ngslib.so)

I installed ngsolve via macports :

ngsolve @6.2.2004 (math)
NGSolve Finite Element Library

My configuration is a MacbookAir with Catalina 10.15.4

According to the line : from .ngslib import version, ngstd, bla, la, fem, comp, solve
and the error message, I tried :
nicolas$ nm -g /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ngsolve/ngslib.so | grep fem

and I obtain :

             U __Z11ExportNgfemRN8pybind116moduleE

so it seems there is no symbol fem in this .so

Thanks for your help


Hi Nicolas,

since there is no reference to the macports port on the NGSolve website, I’m guessing that this is not an official build. It’s probably easiest to use the dmg provided in the downloads section to get a working copy of NGSolve.

Best wishes

Hello Henry,

Thanks for your advice ! it helped me a lot to find a solution.

Before my mail on the forum, I had tried to used directly the dmg but the application didn’t worked. So I tried using the macports.

Thanks to your mail, I came back to the dmg : the reason was that netgen searches Python in /Library/Frameworks and as I used a python installed with macports it was in /opt/local/Library/Frameworks so netgen didn’t find it. So I followed your advice :

  • I uninstalled netgen and netsolve via macports
  • I re-installed netgen via the dmg file
  • I made a symbolic link :
    “ln -s /opt/local/Library/Frameworks/Python.framework” in /Library/Frameworks
    … and it worked !

So even if netgen and netsolve exists under macports, it seems not to be the usual way to use netgen as you said !

Thanks a lot !


The macports installers are not created/maintained by us. If you have troubles with them I guess you need to write to their bugtracker.
Good that you got it working with the dmg :slight_smile: