Issue 126: Can't import pyodbc when using mod_wsgi
Status:  Hold
Owner: ----
Reported by Florian....@gmail.com, Oct 11, 2010
What steps will reproduce the problem?
Use any wsgi-file (the wsgi-sample will do) and put "import pyodbc" on top of it.

What is the expected output? What do you see instead?
I would expect that pyodbc gets imported. But instead an import error occurs - saying that the module could not be found.

What version of the product are you using? On what operating system?
Windows 7, Apache 2.2.16, Python 2.7, mod_wsgi 3.3, pyodbc 2.1.8.
Also happens with different configurations on other windows machines (different os, apache and python).

Please provide any additional information below.
Maybe it has something to do with pyodbc binaries on windows because other non binary modules get imported correctly. This is a fresh system and afaicr i did nothing beside the obvious installation steps. The wsgi-sample and other wsgi-stuff works fine.
Nov 20, 2010
Project Member #1 mkleehammer
I actually use pyodbc on Windows 7 myself, and I'm quite sure it isn't the binaries per se.  You'll need to log out the python path within the web application, which is probably better discussed on the news group: http://groups.google.com/group/pyodbc/topics

I can try to help, but I'm pretty sure this is an Apache configuration issue.

Status: Investigating
Labels: -Type-Defect -Priority-Medium Type-Other Priority-Low
Nov 21, 2010
Project Member #2 mkleehammer
(No comment was entered for this change.)
Status: Hold
Labels: Python2
Mar 27, 2011
#4 zpis...@gmail.com
I got the same problem when I using apache+wsgi+pyodbc2.1.8, but the pyodbc2.1.7 works for me.
Then I compareed the two version, I found the section in 2.1.7
     <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
is become to 
   <dependency>   
  </dependency>
I think that would be the issue.
Mar 29, 2011
#5 Florian....@gmail.com
I don't see how this could be an Apache configuration issue. I'm using the standard configuration + wsgi (about 3 lines added to httpd.conf).

I tried pyodbc 2.1.7 with no luck. I also tried prebuilt binaries for other software that was built using MinGW and these get imported fine.
I checked the pyodbc binaries using Dependency Walker and it said that MSVCR90.DLL was missing. So i tried pyodbc 2.1.7 again using version 9.0.21022.8 of MSVCR90.DLL. On import i get an import error message directly from apache:

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Runtime Error!

Program: C:\Progr...

R6034

An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
---------------------------

I really don't get it - i mean - it's the correct DLL, right?
Apr 25, 2011
#6 dhara...@gmail.com
I'm stuck at the same point.  Slightly different configuration:
Win XP Pro; Python 2.6.5; Apache 2.2.16; PyODBC 2.1.8; WSGI 3.3 ("mod_wsgi-win32-ap22py26-3.3.so")

This post seems to be relevant:
http://groups.google.com/group/modwsgi/browse_thread/thread/13b4a5faa962d77/dd4d6a03afbe16b6

... but I'm stuck, as I really have very little experience in building anything in C under Windows.  According to that post: I have to install Mingw32, and rebuild... what?  PyODBC?  mod_wsgi?

Can the Windows version of [PyODBC | mod_wsgi] just be built that way all the time?

-- Dan






Apr 25, 2011
#7 rocker.y...@gmail.com
I always build pyodbc with MinGW.
It looks impossible to make pyodbc find MSVCR90.DLL. It's terrible.
Does anybody know what should I do to run pyodbc normally under Apache in Windows?
From Python shell it works fine.

Also I have the same problem with many releases of lxml.etree. Only lxml-2.2.2 works without building with MinGW.
I think the reason for this is incorrect dependency information.

Alexander.
May 17, 2011
#8 pland...@gmail.com
http://groups.google.com/group/isapi_wsgi-dev/browse_thread/thread/03fa2b485ec2281d

I believe this issue may be related to the msvc9compiler.py issues mentioned in the above link.   If so, this is really an issue in Python itself, but a workaround may be found by tweaking msvc9compiler.py to remove the Visual C runtime info from the DLL's manifest.  This let me get pyODBC working under IIS / isapi. 

I've attached my modified copy of msvc9compiler.py in case it helps.
msvc9compiler.py
28.8 KB   View   Download
Jul 14, 2011
#9 dom...@gmail.com
Using Python 2.7, mod_wsgi 3.3, Apache 2.2, pyodbc 2.1.8
Comment #8 seems to have helped me.
What didn't help:
* pyodbc 2.1.7
* Python 2.6
* older mod_wsgi, build from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
* building with mingw32

Attached build is what worked for me.
pyodbc-2.1.8.win32-py2.7.exe
227 KB   Download
Oct 4, 2011
#11 dkleeham...@gmail.com
I know this is late, but I've been wrestling with this for months.

The specific problem is with mod_wsgi and apache, not pyodbc or python.  The quickest way to fix this issue is to download Apache built with vc9 C++ binaries.  You can find it here:
http://www.apachelounge.com/download/

However, I was using xampp which just recently (about two weeks from the time of writing this) has released their new package (1.7.7) which contains Apache 2.2 built with the new vc9 C++ binaries.  You can find it here (all of the windows binaries are built with vc9):
http://www.apachefriends.org/en/xampp-windows.html

Both options above will get you back up and working.  Once I installed, I placed my modules in the modules dir and modified the httpd.conf and I was able to import and use pyodbc.

Thanks,

Daniel Kleehammer
Oct 6, 2011
#12 alfr...@gmail.com
Please see issue 214.