Problems with Netgen pip package

Hello Netgen team

In FreeCAD we have implemented meshing via the Netgen Python bindigns. Everything works fine, but some users have reported problems with the pip package.
In my case, I reproduce the error by installing the package in a virtual environment:

mkdir virtual_env                    # create virtual environment directory
python3 -m venv virtual_env          # create virtual env
cd virtual_env/bin                   # move to virtual env
./pip install netgen-mesher          # install netgen mesher for the venv
./python3                            # run python interpreter
import netgen                        # -> Illegal instruction!

I’ve also noticed that *.so shared objects have unresolved dependencies for all OCC libraries:

ldd ./lib/python3.11/site-packages/netgen/libngpy.so
....
libTKOffset.so.7.8.1 => not found
libTKFillet.so.7.8.1 => not found
etc
....

I’ve also tried installing the pip package in a conda environment and forcing pip to install to /usr/local but I get the same error.

For some other users the pip package works fine.

Hello,

The Python packages are compiled for AVX2 CPUs. If the machine is too old (about 10 years), they might not support it. In this case, they need to compile Netgen from source.

Answer to your remarks:
Are you sure your instructions are correct? There is no ./pip inside virtual_env when I run python3 -m venv virtual_env, but bin, include, lib, ... instead.

This works for me in a clean docker environment:

docker run -ti python:3.11 /bin/bash
cd
python -m venv virtual_env
./virtual_env/bin/pip install netgen-mesher
./virtual_env/bin/python -c 'import netgen'

The ldd command shows unresolved libs, because the netgen library cannot know at compile time, where the OCC libs will be at run-time. Thus, we are loading them explicitly during python import, see netgen/python/__init__.py at master · NGSolve/netgen · GitHub

Best,
Matthias

Matthias, thanks for the reply.
AVX2 support explains the problem.
I’m now testing on a machine with AVX2 and the package works fine.
On a CPU without AVX2, the package works up to v6.2.2204 (compatible with Python 3.10)

Are you sure your instructions are correct?..

I made a typo in the post. It’s now fixed.