-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
python - problem with library search order? #3343
Comments
Weird, I can reproduce with mingw64 python but not with mingw32 python. Can you confirm that? |
Indeed! Only happens with mingw64 for me, too. |
You'd need to put the broken DLL in syswow64 for 32 bit. This is just
standard DLL-hell though, no one but Microsoft should put libraries in that
folder and the software doing this is broken and inconsiderate. On Python 3
hashlib depends on openssl much less (if at all).
…On Feb 4, 2018 10:51 AM, "Christoph Reiter" ***@***.***> wrote:
Weird, I can reproduce with mingw64 but not with mingw32.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/Alexpux/MINGW-packages/issues/3343#issuecomment-362897957>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_pdHt3jJ1I6C0bepyiNBXBLT4BuVwkks5tRYvDgaJpZM4R4Zih>
.
|
@mingwandroid ah, thanks. Shouldn't python still prefer the DLL in the directory of the python.exe? |
@lazka, well, the code to load an extension module (ok for Python 3.6 but I think 2.7 will be much the same) is here:
So AFAICT, https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx |
Thanks @mingwandroid . Makes sense, and the order you mentioned would indeed be nicer. From what I see you can get that order by combining LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR and LOAD_LIBRARY_SEARCH_DEFAULT_DIRS, but those are only available with Windows 7. |
Ah ok, good research. We could think to add the executable's dirname to the dll search path somewhere around Python_Init. Am on my phone so cannot find the correct function names ATM! |
Yeah, if the numpy wiki is correct, then
in init might work.
Now I also understand why MSYS2 Python always prepends the executable directory to PATH while the official Python doesn't. Otherwise nothing would be found... |
What about simply using SetDllDirectory and point it to the /bin folder (i.e. where python executable is located)? It seems to work even when python is spawned as a child process by Inkscape, so should be fine for python itself, too, or am I overlooking any edge cases? Seems to be the more reliable method that causes less headaches... |
As long as SetDllDirectory does not undo the effect of LOAD_WITH_ALTERED_SEARCH_PATH, then that sounds more reliable. |
To verify that put the empty LIBEAY32.dll into "/mingw64/lib/python2.7/lib-dynload/" and it should fail despite of SetDllDirectory. |
Ah, that might be a problem... |
Behavior with SetDllDirectory confirmed. Search order is
(i.e. SetDllDirectory in second place and "The directory from which the application loaded" in first place as documented) On a side note: In all those cases I wonder how "C:\Program Files\Inkscape\lib\python2.7" is the first directory searched? It does contain neither the python.exe nor the _hashlib.pyd. Edit: Considering the initial search order and the side note this seems to be actually what we want? As Python does not seem to search in "/mingw64/lib/python2.7/lib-dynload/" at all we do not really loose anything by loosing the effect of LOAD_WITH_ALTERED_SEARCH_PATH that does not really seem to have the effect of searching "The directory specified by lpFileName." in first place... Edit2: Just to confirm this is not a random glitch with hashlib, default load order when loading
Edit3: And to recap my observation from the very first post: If I do the whole thing from within a MinGW shell python immediately loads |
small note: that it searches first in bin seems to be some MSYS patching, starting python with "MSYSTEM= python" makes it search in lib first, but also in lib\python2.7 and not lib-dynload, as you noted. |
Seems python3 is affected, too, see #3381. Interestingly python3 does try to search in "lib-dynload/" so there seems to be a slight difference here. Did we reach a consensus on what the best solution might be?
Any thoughts? |
Some related recent upstream changes for 3.8: python/cpython@2438cdf |
We found an issue downstream where Python searches for libraries of a dynamically linked module (_hashlib.pyd) in an order that makes it likely to cause problems:
_hashlib.pyd is linked against LIBEAY32.dll; when loaded it attempts to load
This is consistent with what is described at
https://github.com/numpy/numpy/wiki/windows-dll-notes
Unfortunately if an incompatible LIBEAY32.dll (or any other DLL that needs to be loaded) is found in one of the system directories the module load fails.
There are easy steps to reproduce this:
I've found that this does not seem to happen when launched from inside an MSYS2 shell (anybody knows what is different in this scenario?).
A workaround for Inkscape seems to be to call SetDllDirectory but for standalone Python that still won't work.
Any ideas what is going wrong and how/where to fix it best? Interestingly python3.6.exe is not affected either, so maybe there is already a solution available?
The text was updated successfully, but these errors were encountered: