NGSolve Import Error: DLL load failed: The operating system cannot run %1

Hello everyone,

I encountered an import error while trying to use NGSolve, with the specific error message “DLL load failed: The operating system cannot run %1”. I have tried reinstalling NGSolve and related dependencies, but the issue persists.


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_18276\2688698555.py in <module>
      2 # with Dirichlet boundary condition u = 0
      3 
----> 4 from ngsolve import *
      5 from netgen.geom2d import unit_square
      6 from ngsolve.webgui import Draw

G:\lib\site-packages\ngsolve\__init__.py in <module>
     33             ctypes.CDLL(str(f.locate()))
     34 
---> 35 from .ngslib import __version__, ngstd, bla, la, fem, comp, solve
     36 
     37 from netgen import Redraw

ImportError: DLL load failed: 操作系统无法运行 %1。

I am using the operating system Windows 10. I have also checked the system environment variable settings, but I still cannot resolve this import error.

I am hoping to receive some guidance on how to resolve this import error. Has anyone encountered a similar issue? Are there recommended solutions or troubleshooting steps?

Thank you very much for your help!

Best regards,
Lee

Please try the newest nightly install with:

pip install --pre ngsolve

What seems to be the issue? May I ask for your guidance on what to do?

C:\Users\lenovo>pip install --pre ngsolve
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement ngsolve (from versions: none)
ERROR: No matching distribution found for ngsolve

Maybe pip3 install --pre ngsolve?

Same as just now

C:\Users\lenovo>pip3 install --pre ngsolve
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement ngsolve (from versions: none)
ERROR: No matching distribution found for ngsolve

pip install ngsolve==6.2.2401.post24.dev0

I have followed your instructions as prompted.Could you please help me identify what the problem is?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_12412\2688698555.py in <module>
      2 # with Dirichlet boundary condition u = 0
      3 
----> 4 from ngsolve import *
      5 from netgen.geom2d import unit_square
      6 from ngsolve.webgui import Draw

d:\ProgramData\anaconda3\lib\site-packages\ngsolve\__init__.py in <module>
     19 if config.is_python_package and sys.platform.startswith('win'):
     20     netgen_dir = os.path.dirname(netgen.__file__)
---> 21     os.add_dll_directory(netgen_dir)
     22     os.environ[\"PATH\"] += os.pathsep + netgen_dir
     23 

AttributeError: module 'os' has no attribute 'add_dll_directory'"

what operating system and python version do you have?

windows10 python3.7.16

Could you upgrade you Python Version?
os.add_dll_directory needs at least Python 3.8.
os — Miscellaneous operating system interfaces — Python 3.12.2 documentation