SOLVED: ngsxfem installation ubuntu 16.4

Hi, I made the installation (ubuntu 16.4) without any mistake for both packages ngsolve and ngsxfem. ngsove works perfectly but related to the ngsxfem the 17/18 of the preliminary tests fail and when I am trying to execute files of the ngsxfem py_tutorials e.g. the, I see the message
" File “”, line 75, in
ImportError: No module named ‘xfem’"

and in particular:
ubunt164@ubunt164-VirtualBox:~$ netgen
Developed by Joachim Schoeberl at
2010-xxxx Vienna University of Technology
2006-2010 RWTH Aachen University
1996-2006 Johannes Kepler University Linz
Including OpenCascade geometry kernel
optfile ./ng.opt does not exist - using default values
togl-version : 2
OCC module loaded
loading ngsolve library
Using Lapack
Including sparse direct solver Pardiso
Including sparse direct solver UMFPACK
Running parallel using 1 thread(s)
importing NGSolve-6.2.1709
(should) load python file ‘/home/ubunt164/ngsxfem/py_tutorials/’
Traceback (most recent call last):
File “”, line 75, in
ImportError: No module named ‘xfem’
Finished executing /home/ubunt164/ngsxfem/py_tutorials/
Thank you for using NGSolve

could you help me please? Thank you!

Hi Karatzka,
where did you install ngsxfem to? It seems, that you have to add the folder of the ngsxfem python module to the environment variable PYTHONPATH.


Dear Christopher,

Thank you for your quick response! I used the instructions for Building xfem with pre-installed NGSolve: git clone GitHub - ngsxfem/ngsxfem: Add-On to NGSolve for unfitted finite element discretizations (XFEM, CutFEM, TraceFEM, etc...)
cd ngsxfem
mkdir build
cd build

cmake …/ -DINSTALL_DIR=/home/ubunt164/ngsxfem/build -DBUILD_NGSOLVE=OFF
make install

So I installed it to /home/ubunt164/ngsxfem/build … should I have used another path to make it work automatically maybe?

How can I please add the folder of the ngsxfem python module to the environment variable PYTHONPATH?

With kindest regards
Makis Karatzas

Dear Makis,

It’s a bit unusual to install into your build directory.

export PYTHONPATH="${PYTHONPATH}:/home/ubunt164/ngsxfem/build/lib/python3.6/site-packages
to add the install-directory to your python path. Note that the directory may depend on your python version; so: check which directory exists.


Dear Christoph,

I tried the one you suggested but it didn’t work so I made the installation again and this time I installed it in /usr/bin/, where netgen was already installed. However, during ‘make install’ part of the installation, it was giving me permission denied error and I used sudo apt to make install and make install worked.
xfem is still not found and for pythonpath, my /usr/bin/ has python2 and python3 installed. My computer uses python2 but since these pythons are directly installed in /usr/bin/, I don’t know to which python should I do the python path and how?

Dear Makis,

Sorry for the late reply.

I am not sure why things are not working for you.

Can you please do the following:

Can you please check the paths that are shown after you type

(sudo ...) make install


Check where the file is installed to.
It should say something like

-- Installing: /INSTALLLOCATION/lib/python3.6/site-packages/xfem/

With the installation to /usr/lib, your INSTALLLOCATION is probably just /usr

Afterwards make sure to set your python path correctly, i.e.

export PYTHONPATH="${PYTHONPATH}:/INSTALLLOCATION/lib/python3.6/site-packages

You can check your PYTHONPATH environment variables with typing

export | grep PYTHONPATH 

Try the installation (from the same terminal from where you exported the PYTHONPATH) with running a tutorial-file of xfem with netgen or python3.

If this is still not working, please post
[li]the lines from step 1. from the make install command[/li]
[li]the resulting PYTHONPATH from step 2.[/li]
[li]the error that you obtain from 3.[/li]

Best of luck,

Dear Christoph,

It worked perfectly using python3, thank you for your helpful detailed instructions and the very fast responses,

best wishes and thanks