New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't import module created by f2py "ImportError: DLL load failed" #16416
Comments
I see traces of |
Hi @mattip, although I wasn't able to use |
You can try using depends.exe to see what other dlls |
I have been going through those threads and looking at my installation. It seems that indeed i don't have |
I use |
For me it is named |
I just installed using chocolatey and the same thing continues to happen.. I tried looking for any |
Also, using the depends.exe you mentioned, and opening the generate pyd file, i get the following error:
|
That is normal, even for well-behaved DLLs.
Dunno, I just followed the recipe and it worked. After you install chocolatey (with admin permissions), you may need to open a new DOS window (as a regular user) so the PATH changes percolate through. Maybe a chocolatey forum might be able to help more. |
I see. I installed with admin permissions and opened a new DOS windows afterwards, but still the libgfortran dll wasn't there. Could you tell in which folder yours was located? |
I reported that above |
@danvip10 is this issue still active? It sounds like the gremlin likely lies in system configuration rather than something that is NumPy-specific. It may not be much help, but buried in the azure-steps-windows.yml is a procedure for configuring a windows system for the CI. |
Hi @rossbar, the issue is indeed still active. I will give it a try with what you suggested. |
Hello @danvip10 |
Hey oussamazt this command was able to work for me Don't ask my why it worked |
Hi @oussamazt I haven't been able to solve the problem because I've been using MacOs lately and haven't installed this yet. Let me know if the approach proposed by @zlamere works for you though. |
I had the exact problem recently and the solution is to download the required Microsoft Visual C++ 14.0. This page well explains what you need to do: https://www.scivision.dev/python-windows-visual-c-14-required/ |
This seems to be an issue of poor documentation, and not a true bug. Should be closed with a PR to improve the docs. |
Hi, I came across the same issue when I tried to build PyTMatrix on Windows.
The main package is pytmatrix and it includes an f2py-based extension module named pytmatrix.fortran_tm.pytmatrix.
The libampld.lp.XN4PNFVBPLZONUAMUJEXLEI7ZJ4CLFGY.gfortran-win_amd64.dll file is created by f2py from the Fortran files that the pytmatrix.fortran_tm.pytmatrix module is intended to wrap. When pytmatrix.fortran_tm.pytmatrix is imported, the following error is thrown.
I digged into the cause of the error, and identified that the pytmatrix.cp39-win_amd64.pyd module failed to find libampld.lp.XN4PNFVBPLZONUAMUJEXLEI7ZJ4CLFGY.gfortran-win_amd64.dll. I also learned that on Windows, DLLs need to be in the same directory with the executable file (otherwise some other system directories are searched), and that Windows does not have a linker option equivalent to -rpath available in Linux/Unix. I could not find distutils/f2py options to meet this requirement, so I revised the numpy.distutils code to achieve the required DLL file location (see attachment).
And I was finally able to import the pytmatrix.fortran_tm.pytmatrix module without an error and run the Fortran code in it correctly. Obviously the revised distutils code has not been tested much, but I hope it provides a starting point for a better solution. build_ext_rev2.patch.txt |
Thanks so much! This resolved a big stumbling block for me. I put the *.dll file together with the *.pyd as you suggested and can now import. Thank you for your detailed post. |
Works if you try out the following configuration: Any recent CPython 64-bit version UCRT64 Msys2 GCC toolchain, i.e.:
and the following command line:
The flag Without this flag one gets a gfortran compiled and linked |
I propose to close this issue. |
I think a documentation PR should close this as mentioned earlier.
Please feel free to take it up if you'd like. The right location to make changes can be seen in the Windows F2PY documentation PR (rendered here) |
I wasn't aware of the newer f2py docs, thanks @HaoZeke. I will take a look. |
I had the exact same problem. The solution I found was to do everything from MSYS2 CLANG64. I don't personally like this solution but, it works for now. |
Closing since the new documentation has quite a bit on Windows builds (mostly now we just suggest offloading to the SciPy configuration with |
I'm trying to use f2py to use some fortran code. I am trying to reproduce the example in the documentation of f2py
System: Windows 10
Python: Python 3.7.7 [MSC v.1916 64 bit (AMD64)]
numpy: 1.18.1
I installed mingw64 and also the Visual C++ Redistributable after seeing some answers in SO suggesting that. However nothing has worked.
I have the file fib1.f:
In the same folder I run
python -m numpy.f2py -c fib1.f -m fib1
and that runs fine. It outputs:However, when I go into python and run
import fib1
, i get the following error:The same thing happens if I use an .f90 file or the 2nd method in documentation
The text was updated successfully, but these errors were encountered: