Skip to content
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

Importing example project fails on fresh Windows 7 installation #1083

Closed
YannickJadoul opened this issue Sep 13, 2017 · 8 comments
Closed

Importing example project fails on fresh Windows 7 installation #1083

YannickJadoul opened this issue Sep 13, 2017 · 8 comments

Comments

@YannickJadoul
Copy link
Collaborator

The cmake_example project fails to be imported on a fresh Windows 7 installation, throwing the immensely informative exception ImportError: DLL load failed: The specified module could not be found.

Upon further inspection, using the depends tool for Window DLLs, it seems that this is because MSVCP140.DLL cannot be found. As far as I know, this is MSVC's C++ standard library. Is there a way to get around this, or is the only way to solve it to tell users to install the C++ redistributable libraries?

Next to that, while investigating and reading up on this issue, I found that to build a binary Python extension, developers are urged to make sure the standard library DLLs that are linked against to be the same as the ones the official Python was built against (e.g., https://matthew-brett.github.io/pydagogue/python_msvc.html, or http://stevedower.id.au/blog/building-for-python-3-5/). I however found that the pybind11 examples were referencing the VS 2015 DLL, VCRUNTIME140.DLL (as they were built on AppVeyor with VS 2015). Next to that, the issue with using the offical compiler Microsoft released to ensure compatibility with Python 2.7 (https://www.microsoft.com/en-us/download/details.aspx?id=44266) is so old that it doesn't support C++11. Any thoughts/reassurances on this? Will the Python extensions that I build this way work, even when I would start using more advanced features of the C/C++ standard libraries that have changed between different DLL versions?

Additional links:

@henryiii
Copy link
Collaborator

Have you read the FAQ? It seems to answer one of your questions: http://pybind11.readthedocs.io/en/master/faq.html#working-with-ancient-visual-studio-2009-builds-on-windows

And, if you are on Windows, I would recommend Python 3 if possible! :)

@YannickJadoul
Copy link
Collaborator Author

YannickJadoul commented Sep 13, 2017

Ah, damn, no, I had missed that! That does mostly solve the second part of my question, indeed.
It's a bit weird that I'm reading that these specific compiler versions should be used, then, though (and especially that Miscrosoft released that special compiler for 2.7?).

The first part, with the MSVCP140.DLL still completely holds, though, since it's not there on a fresh Windows 7. For Python 2.7, 3.4, 3.5, as well as 3.6.

Also, on the Python 3 suggestion: it's not just me. Distributing my package on PyPI, I would prefer to still offer Python 2...

@henryiii
Copy link
Collaborator

Ahh, libraries, yes 2.7 still is needed there. 😞 . And I think you have to either ask for the redistributable library to be downloaded, or you can redistribute it (probably can't be done on PyPI, though). Someone else might know more, though, I've not used Windows (save for AppVeyor) in several years...

I wonder if the error message could be made more helpful?

@YannickJadoul
Copy link
Collaborator Author

Yes, that's why I'm asking, indeed. I prefer to stay away from Windows as well, but quite a lot of my user base might not think the same :-(

And even if there's no better way, we could/should probably add something to the documentation about this redistributable.

The error message is Python forwarding Windows' error message, I think. Just guessing, but ImportError: comes from the Python exception, DLL load failed: is most likely prepended by Python internally, and The specified module could not be found. would then be the error message from Windows. And since the pybind11 module can't even be loaded, I wouldn't expect pybind11 to be able to make this more informative?

@YannickJadoul
Copy link
Collaborator Author

Also, what about this whole thing with setting DISTUTILS_USE_SDK=1 and MSSdk=1? (see e.g. https://stackoverflow.com/questions/11267463/compiling-python-modules-on-windows-x64/13751649#13751649)

Is that also unnecessary when using the latest MSVC version?

@henryiii
Copy link
Collaborator

From your end, if you provide a pure Python wrapper you can. I call the module _extension.so and then put it in a folder named extension, with __init__.py inside, with contents: from _extension import *, so in that setup you could add a try/catch block.

@YannickJadoul
Copy link
Collaborator Author

Hmmm, true, I could keep that in mind. Thanks for the idea! (Might still be messy to catch the exact right errors, and not all the ImportErrors, since I don't know about the localization of that Windows message, etc, etc)

@YannickJadoul
Copy link
Collaborator Author

Let me close my own issue as well. Thanks for the help, back then, @henryiii!

For future reference, I ended up just making a note in my docs:

https://parselmouth.readthedocs.io/en/stable/installation.html#importerror-dll-load-failed-on-windows

Sometimes on Windows, the installation works, but importing Parselmouth fails with an error message saying ImportError: DLL load failed: The specified module could not be found.. This error is cause by some missing system files, but can luckily be solved quite easily by installing the “Microsoft Visual C++ Redistributable for Visual Studio 2017”.

The “Microsoft Visual C++ Redistributable for Visual Studio 2017” installer can be downloaded from Microsoft’s website, listed under the “Other Tools and Frameworks” section. These are the direct download links to the relevant files:

For a 64-bit Python installation: https://aka.ms/vs/15/release/VC_redist.x64.exe
For a 32-bit Python installation: https://aka.ms/vs/15/release/VC_redist.x86.exe

To check which Python version you are using, you can look at the first line of output when starting a Python shell. The version information should contain [MSC v.xxxx 64 bit (AMD64)] in a 64-bit installation, or [MSC v.xxxx 32 bit (Intel)] in a 32-bit installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants