Cannot import name 'Redraw' from 'netgen'

Hello ngsolve / netgen developers, I’m using ngsolve and seeing the following error:

File “/home/rong1tang/FSI/FSI_h.py”, line 78, in
from ngsolve import *
File “/home/rong1tang/anaconda3/envs/Test/lib/python3.12/site-packages/ngsolve/init.py”, line 36, in
from netgen import Redraw, TimeFunction
ImportError: cannot import name ‘Redraw’ from ‘netgen’ (/home/rong1tang/anaconda3/envs/Test/lib/python3.12/site-packages/netgen/init.py)

The error occurs at the following line:

from ngsolve import *;

Not sure if it’s relevant but I only see this when running it on a Linux server without GUI. On mac os x I’m able to run it without issue.

Could you help me address this issue? Thanks a lot!

you seem to have incompatible ngsolve netgen installations. Can you upgrade them and see if the error persists?

python -m pip install --upgrade ngsolve

Thanks, I have tried it just now but the issue still exists.

is your netgen and ngsolve taken from the same path?
you can test something like

import netgen
import ngsolve
print(netgen.__file__)
print(ngsolve.__file__)

and it should be smth like some_path/netgen/__init__.py and some_path/ngsolve/__init__.py
if the paths are different something else might have installed netgen into your python environment with a different version.

Thanks for the advice. I have tried it but the same issue exists:

Traceback (most recent call last):
File “/home/rong1tang/FSI/server.py”, line 2, in
import ngsolve
File “/home/rong1tang/anaconda3/envs/Test/lib/python3.12/site-packages/ngsolve/init.py”, line 36, in
from netgen import Redraw, TimeFunction
ImportError: cannot import name ‘Redraw’ from ‘netgen’ (/home/rong1tang/anaconda3/envs/Test/lib/python3.12/site-packages/netgen/init.py)

Is it possible you have another netgen package installed?
‘pip uninstall netgen’

Please try the following:

>>> import netgen
>>> netgen.__file__
'/Applications/Netgen.app/Contents/Resources/lib/python3.13/site-packages/netgen/__init__.py'
>>> from netgen import Redraw
>>> import ngsolve
>>> import netgen
>>> netgen.__file__
'/home/rong1tang/anaconda3/envs/Test/lib/python3.12/site-packages/netgen/__init__.py'
>>> from netgen import Redraw
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Redraw' from 'netgen' (/home/rong1tang/anaconda3/envs/Test/lib/python3.12/site-packages/netgen/__init__.py)

it still does not work. Thanks.

There is a Redraw function in netgen/__init__.py since 2 years.
It looks like you have an old Netgen. Note, the pip package is netgen-mesher.

Thank you so much! It works.