tomlxq / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

pyodbc.pyd does not embed the correct manifest for the msvc runtimes on windows #214

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by alfr...@gmail.com on 6 Oct 2011 at 2:39

GoogleCodeExporter commented 8 years ago
I should add that the pyd files can typically be found in your user-specific 
egg installation path or the lib\site-packages subdirectory of your python 
installation, depending on installation method.

Original comment by alfr...@gmail.com on 6 Oct 2011 at 2:44

GoogleCodeExporter commented 8 years ago
I just tested this on my Windows 64bit with 32bit python. Then tryed to import 
pyodbc in gvim and it works :) Thanks

Original comment by dusan.sm...@gmail.com on 7 Oct 2011 at 9:31

GoogleCodeExporter commented 8 years ago
Great tip! The autocomplete when using scripts with pyodbc on vim "cream" on 
windows 32 bits is working Ok.
Many Thanks :)

Original comment by anibal.m...@gmail.com on 10 Oct 2011 at 2:59

GoogleCodeExporter commented 8 years ago
Thank you! This solution makes it possible to use pyodbc in Python apps running 
under mod_wsgi on Apache.

Original comment by kpozin@gmail.com on 31 Oct 2011 at 6:04

GoogleCodeExporter commented 8 years ago
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).

Original comment by mkleehammer on 3 Nov 2011 at 2:10

GoogleCodeExporter commented 8 years ago
any idea when you will have updated prebuilt binaries?

Original comment by drmap...@gmail.com on 3 Nov 2011 at 6:07

GoogleCodeExporter commented 8 years ago
Great!It works. Thank you very much!

Original comment by gude...@gmail.com on 18 Jan 2012 at 4:08

GoogleCodeExporter commented 8 years ago
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-pyo
dbc-import-problems

Original comment by jnr...@gmail.com on 17 May 2012 at 5:15

GoogleCodeExporter commented 8 years ago
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

Original comment by gimbus...@gmail.com on 29 May 2012 at 4:11

GoogleCodeExporter commented 8 years ago
Thanks! Saved my day!

Original comment by fgmac...@gmail.com on 5 Feb 2013 at 7:59