thliebig / openEMS-Project

openEMS is a free and open electromagnetic field solver using the FDTD method.
356 stars 65 forks source link

ImportError : DLL load failed, after installing as per install instructions #198

Closed MaximGi closed 2 months ago

MaximGi commented 2 months ago

Following instructions at link :

The following exceptions are raised while trying to import either of both CSXCAD and OpenEMS Modules :

Open EMS traceback

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\maxim\python\ml2023\Lib\site-packages\openEMS\__init__.py", line 7, in <module>
    import CSXCAD
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\maxim\python\ml2023\Lib\site-packages\CSXCAD\__init__.py", line 19, in <module>
    from CSXCAD.CSXCAD import ContinuousStructure
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing CSXCAD: Le module spécifié est introuvable.

CSXCAD traceback

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\maxim\python\ml2023\Lib\site-packages\CSXCAD\__init__.py", line 19, in <module>
    from CSXCAD.CSXCAD import ContinuousStructure
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing CSXCAD: Le module spécifié est introuvable.
thliebig commented 2 months ago

Can you please try this with a plain simple python (not via JetBrains)? It seems to me that JetBrains uses its own wired import method (not sure)? What I prefer on Windows is WinPython and this is the only way I have tested this so far.

thliebig commented 2 months ago

What you can try too is in your script tell python where to look for the *.dll with:

os.add_dll_directory(r'C:\opt\openEMS')

MaximGi commented 2 months ago

OK, I found a way to keep working with Pycharm + virtual env.

It is possible to use this workaround :

What you can try too is in your script tell python where to look for the *.dll with:

os.add_dll_directory(r'C:\opt\openEMS')

Or, just add C:\opt\openEMS or whatever the directory is as as source directory in the pycharm project.

In a more general way, do you think it is possible to package all of this into a Pypi namespace so openEMS can be installed directly with pip ? I'm only suggesting, not demanding because I'm not competent enough to do it.