| Issue 214: | pyodbc.pyd does not embed the correct manifest for the msvc runtimes on windows | |
| 12 people starred this issue and may be notified of changes. | Back to list |
I believe this will resolve open issues 126, 171, 181, 185, and 187 Dependency walker indicates that pyodbc.pyd depends on msvcr90.dll. It appears that this dependency is being satisfied by running inside of python.exe (which is linked against the same). When the dll version of the python interpreter is instead hosted by another process, the windows sxs configuration applies the msvcr90 dependency only to the python dll. This means that, in general, pyodbc.pyd (and likely pyodbcconf.pyd) will be unusable in embedded python on windows unless the host application is linked against the appropriate version of the msvc runtimes. Because of how SxS dlls work it does not suffice to simply drop the msvc runtime dlls into the dll search path, instead the correct version of the runtime must be installed to the system and referenced in the dll's manifest. (I believe trying to load the mvcr90 dll from the search path is the cause of the R6034 error in issue 181) Since pyodbc works inside of python, it suffices to embed the python27.dll's manifest into the pyds. As a work-around this can be done directly to the pyd's by using the manifest tool (mt.exe - a freely available tool in the windows sdk) with the commands below. You will likely need to adjust the paths to suit your own needs. mt.exe -inputresource:c:\windows\syswow64\python27.dll;#2 -outputresource:pyodbc.pyd;#2 mt.exe -inputresource:c:\windows\syswow64\python27.dll;#2 -outputresource:pyodbcconf.pyd;#2 Alternatively you can try extracting the manifest from python.exe by changing the inputresource argument to -inputresource:c:\python27\python.exe;#1. I have not tested importing the manifest from the exe but I expect that it works.
Oct 6, 2011
#1
alfr...@gmail.com
Oct 7, 2011
I just tested this on my Windows 64bit with 32bit python. Then tryed to import pyodbc in gvim and it works :) Thanks
Oct 10, 2011
Great tip! The autocomplete when using scripts with pyodbc on vim "cream" on windows 32 bits is working Ok. Many Thanks :)
Oct 31, 2011
Thank you! This solution makes it possible to use pyodbc in Python apps running under mod_wsgi on Apache.
Nov 2, 2011
Thank you for the excellent description. I am embedding Python 2.7 in a number of Windows services and they always work, but I would bet I'm using the exact same service pack level that was used to build Python 2.7. I am guessing that the other apps being embedded into, such as Apache, are at a different level. The stupidity of Microsoft's design here can't be overstated. Fortunately they've removed this nonsense in VS 2010. Unfortunately they didn't back port it. Since pyodbc can be built for Python 2.4-2.7 and 3.2+, I'll try copying the manifest from whatever version of python is being used to build pyodbc. I looked into mt.exe before, but I was pretty sure you were required to have the Windows SDK installed, which I hate to add to the prerequisites (though most people probably use prebuilt binaries).
Status:
Investigating
Nov 3, 2011
any idea when you will have updated prebuilt binaries?
Jan 17, 2012
Great!It works. Thank you very much!
May 17, 2012
It looks like this is a solid fix, and I'd love to apply it, but I'm having trouble with the command. I'm a Linux guy, and the Windows command line frightens and confuses me. To make matters worse, I get different errors in different shells. I posted a question on Stack Overflow with the details. I'd be immensely grateful to anyone who could point me in the right direction so I can get my app deployed. http://stackoverflow.com/questions/10626807/correct-mt-exe-syntax-to-resolve-pyodbc-import-problems
May 28, 2012
Thanks for this solution. It saved the rest of hair on my head ;-) I was wondering why everything worked great with python 2.7.0.2/pyodbc 2.1.8 and did not with python 2.7.2.5/pyodbc 3.0.2 but only under apache/wsgi, from python console everything was OK. Thanks again
Feb 5, 2013
Thanks! Saved my day! |