ImportError: DLL load failed while importing devsim_py3

Hi Juan,
i have been using devsim on linux (debian12) without any issues.
However on windows 11 I get the following error.

File C:\work\py311\Lib\site-packages\devsim\__init__.py:8
    from .devsim_py3 import *

ImportError: DLL load failed while importing devsim_py3: Das angegebene Modul wurde nicht gefunden.

In my windows OS I am using python environment (pip not anaconda) with python 3.11.
I installed mkl-2024.2.2 and devsim 2.8.4
I read also
https://forum.devsim.org/t/installation-issue/74/15?u=saidon70
without solution. I am wondering that nobody else have this issue. do yo have any idea which dll is missing.
Thanks,
Said

Hello @Saidon70,

Please try installing the Visual Studio Runtime:

If that doesn’t work, there is a utility that you can try to identify the missing library:
https://github.com/lucasg/Dependencies

Please let me know if you are able to resolve the issue

thanks for the quick reply. I installed VC++ described above but this did not help.
In the the second options which binary should i use? devsim_py3.pyd?
Thanks,
Said

using devsim_py3.pyd as input returns that python3.dll and zlib.dll are missing.
Regards,
Said

I installed zlib.dll for 64 bit but no success.
Regards,
Said

Which python distribution are you using? Where did you get it from?

For Anaconda python:

conda install zlib

For the dependencies program, you need to use python.exe as the input, not devsim_py3.pyd.

python.exe has no missing dependencies. Therefor, I think that zlib.dll could be the right path.
I downloaded zlib for 64bit and put it in the devsim folder.
Now the dll error is gone but a new one appears:

%runfile C:/work/python_scripts/devsim/si_pin_diode.py --wdir
problems with creating default derivatives. declare(dBdx(x)); define(B(x),dBdx(x)); declare(sgn(x)); declare(step(x)); define(abs(x), sgn(x)); declare(derfdx(x)); declare(derfcdx(x)); define(erf(x), derfdx(x)); define(erfc(x), derfcdx(x));declare(derf_invdx(x)); declare(derfc_invdx(x)); define(erf_inv(x), derf_invdx(x)); define(erfc_inv(x), derfc_invdx(x));declare(dFermidx(x)); declare(dInvFermidx(x)); define(Fermi(x), dFermidx(x)); define(InvFermi(x), dInvFermidx(x)); define(vec_sum(x),1);declare(vec_max(x));declare(vec_min(x));declare(dot2d(ax,ay,bx,by));define(dot2d(ax, ay, bx, by), bx, by, ax, ay);define(max(x, y), x >= y, x < y);define(min(x, y), x <= y, x > y);define(kahan3(a, b, c), 1, 1, 1);define(kahan4(a, b, c, d), 1, 1, 1, 1);define(asinh(x), ((1 + (x^2))^(-1/2)));define(acosh(x), (((x^2) - 1)^(-1/2)));define(atanh(x), ((1 - (x^2))^(-1)));declare(cosh(x));define(sinh(x), cosh(x));define(cosh(x), sinh(x));declare(tanh(x));define(tanh(x), 1 - pow(tanh(x), 2));declare(dgfidx(x,y));define(gfi(x,y), dgfidx(x,y), 0);declare(digfidx(x,y));define(igfi(x,y), digfidx(x,y), 0);
dBdx has already been declared with 1 argument(s)
sgn has already been declared with 1 argument(s)
step has already been declared with 1 argument(s)
derfdx has already been declared with 1 argument(s)
derfcdx has already been declared with 1 argument(s)
derf_invdx has already been declared with 1 argument(s)
derfc_invdx has already been declared with 1 argument(s)
dFermidx has already been declared with 1 argument(s)
dInvFermidx has already been declared with 1 argument(s)
vec_max has already been declared with 1 argument(s)
vec_min has already been declared with 1 argument(s)
dot2d has already been declared with 4 argument(s)
cosh has already been declared with 1 argument(s)
tanh has already been declared with 1 argument(s)
dgfidx has already been declared with 2 argument(s)
digfidx has already been declared with 2 argument(s)
Traceback (most recent call last):

  File C:\work\py311\Lib\site-packages\spyder_kernels\customize\utils.py:209 in exec_encapsulate_locals
    exec_fun(compile(code_ast, filename, "exec"), globals)

  File c:\work\python_scripts\devsim\si_pin_diode.py:11
    from devsim import *

  File C:\work\py311\Lib\site-packages\devsim\__init__.py:8
    from .devsim_py3 import *

RuntimeError: Issues initializing DEVSIM.

Maybe the zlib.dll has the wrong version.
Regards,
Said

It looks like the dll issue is resolved.

It looks like the devsim module is being imported multiple times. This should not be possible from the command line execution from a script, so you may be using some type of python notebook.

Could you please try first running your script as a standalone script from the command terminal?

I’m not sure how to debug this spyder issue.

yes you are right! when running outside spyder the error is now different

(py311) PS C:\work\python_scripts\devsim> python .\si_pin_diode.py
Searching DEVSIM_MATH_LIBS="libopenblas.dll;liblapack.dll;libblas.dll"
Loading "libopenblas.dll": MISSING DLL
Loading "liblapack.dll": MISSING DLL
Loading "libblas.dll": MISSING DLL
Error loading math libraries.  Please install a suitable BLAS/LAPACK library and set DEVSIM_MATH_LIBS.  Alternatively, install the Intel MKL.
Could not find Intel MKL. The maximum tested version is "mkl_rt.2.dll"
Windows returned error 126 while trying to load "libopenblas.dll"
Windows returned error 126 while trying to load "liblapack.dll"
Windows returned error 126 while trying to load "libblas.dll"
Traceback (most recent call last):
  File "C:\work\python_scripts\devsim\si_pin_diode.py", line 11, in <module>
    from devsim import *
  File "C:\work\py311\Lib\site-packages\devsim\__init__.py", line 8, in <module>
    from .devsim_py3 import *
RuntimeError: Issues initializing DEVSIM.
(py311) PS C:\work\python_scripts\devsim>

It looks like some libraries are missing. I thought if numpy is installed these libraries would be automatically be installed.
Regards,
Said

It is weird because mkl_rt.2.dll is already installed

Now I put mkl_rt.2.dll and mkl_intel_thread.2.dll in the devsim directory. The errors disappeared but the python kernel crashes :slight_smile:
In general it looks like devsim is not using Library/bin/ as path to look for these files.

Regards,
Said

Hi @Saidon70,

Please try setting DEVSIM_MATH_LIBS to the full path to mkl_rt.2.dll. This file has many dll dependencies, so it is best to use the full path.

I don’t really know what python distribution you have installed, or whether you are using a virtual environment. I have only tested Anaconda on Windows, so

I would need to do some more testing on Windows to support other distributions.

Where did you get your python distribution?

I got python from here:
https://www.python.org/downloads/release/python-3110/

and I am using virtual environment using python -m venv myvenv

and then I installed all the packages that I need for my daily work using pip install mypackages
On linux I am using the same procedure and everything works fine.
Regards,
Said

If you are using the windows command line, set the environment variable:

set PATH=c:/Users/juan/venv/Library/bin;%PATH%

where the path is the full path to your Library/bin directory. That should fix the issue with the mkl library. You still need to provide your own zlib.dll or set the PATH variable to its location.

So far, I have only worked with Anaconda python on windows. I see now that I also need to support the python.org version.

Please let me know if this works.

Dear Jaun,
thank you very much for you time and support.
I used to use anaconda 2 years ago befor they started charging licensing fees for enterprises. Therefore I switch to the conventional pip packagig manager.
I will try you suggestions tomorrow and keep you updated.
Regards,
Said

Hi Said,

Thanks for bringing this to my attention. I will work on making this process automatic so it will find the mkl dll’s in the Library/bin directory, and maybe statically link in zlib.dll.

Dear Juan,
I copied the content of Library\bin\ to site-packages\devsim.
Now the simulation runs without any error.
I guess, adding the path as suggested above would solve the problem as well but I did not try it.

Regards,
Said

Hi @Saidon70

I’m glad you got it working. Please let me know if you have any additional issues. I’m working on a release to resolve the zlib.dll issue. It looks like setting PATH, DEVSIM_MATH_LIBS, or just copying the mkl files will work.