MySQL and Python 2.6 on Windows, Redux

As I noted before, getting a version of MySQLdb that works for Python 2.6 on Windows is an exercise in frustration.  Until now.

An anonymous commenter on the previous post pointed to a web page with instructions for compiling MySQLdb with Visual Studio.  This was quite the salvation to me as I have no experience with Visual Studio or really any sort of compiling on Windows at all.

The only thing lacking in those instructions is the bit about “vsvars32.bat”.  It says:

make sure “vsvars32.bat” exists in “C:\Program Files\Microsoft Visual Studio 8\Common7\Tools”

That’s the last mention of that file.  The problem is that you have to actually run that batch file prior to compiling.

The only other adjustments I had to make were to account for the fact that I’m using Visual Studio 2008 which has a different path than Visual Studio 2005.

All that resulted in my own Windows installer for MySQLdb for Python 2.6.  This was compiled on Windows 7 64-bit, I’m not sure how it’ll work on other operating systems, but if it doesn’t work for you make a comment and I’ll see if I can compile a version for your environment.

Download it here.

  1. Hey, thanks for this posting! I got this to work on my Windows 7 64-bit system, but only using python 32-bit. It didn’t work on another Win7 64-bit machine I have that’s using python 64-bit. Any clue as to a compile option for 64-bit?

  2. Workaround: download one of these pre-compiled versions for Windows 64-bit or win32: http://www.codegood.com/archives/4

    If you get the error that python version 2.6 is not found in the registry, just manually add the keys to create:

    HKLM\Software\Python\PythonCore\2.6\InstallPath

    and change the value of (Default) to “C:\python26” or your own

    Installation of the above files should work then.

  3. First, thanks to all trying to get this to work!

    I’m thoroughly confused though. I’m using Windows 7 and I downloaded MySQL to its default suggested location (c:\program files(x86)\MySQL) and Python 26 to its corresponding x86 directory. I’m assuming the 2 .msi files knew that they were 32bit versions. I then downloaded the file suggested here and ran it from its download location – the installer screen came up and recognized the Python26 installation but when I clicked “Next” to execute the install it froze then a pop-up let me know that it stopped. I tried this several times. Does it need the MySQL service running during this install? Any other thoughts?
    Thanks!
    Gil

  4. You don’t need to install MySQL to use MySQLdb. MySQLdb is completely self contained.

    For example, I have the MySQLdb package I wrote about in the post installed on this PC, and I don’t have MySQL installed at all.

    The only place you need to have MySQL installed is on the server you’re going to be querying with MySQLdb.

  5. Dustin,

    are you saying that MySQLdb is self-contained in the sense that it has a DB like sql-lite?

    Or are you saying that you can install MySQLdb without having MySQL installed but then need to install MySQL to actually store any data?

    In any case I’ve tried to use the .exe files for both Python 2.5 and 2.6 to install MySQLdb and once they start installing the screen freezes then informs me that the program stopped. I’m using Win 7 and I uninstalled MySQL.

    Any ideas?
    Thanks,
    Gil

  6. @gilnyc:

    MySQLdb doesn’t require or benefit from having MySQL installed on your computer.

    To save data to a MySQL database, you of course have to have access to a MySQL server…whether that server is remote or local it does not matter. I don’t think having MySQL installed locally is a common scenario.

    I dont know anything about a .exe file for Python 2.5 as I only provided a version for Python 2.6. This leads me to believe you’re using a version from one of the links people have provided in the comments. I don’t know anything about those other than the fact that I was never able to find a version that would install for me. Which is the reason I compiled my own.

    The one I provide in the original post works for me.

  7. So here’s how I got it to work: Windows 7 has 2 Program File directories (one for 32 bit and one for 64 bit) and so not to confuse the Python installation I changed its install directory from the default (c:\python26) to the 32 bit location (c:\Program Files (x86)\python26). Python installed fine however the .exe files I found for MySQLdb failed to install (I tried this for both python 2.6 & 2.5 with corresponding MySQLdb executables). Finally I reinstalled python in its default directory (c:\python26) and moved the MySQLdb executable to that directory and ran it from there. MySQLdb installed fine so one of my two changes fixed the problem. Confusing because the MySQLdb executable messages that it finds the python install in the registry yet can’t adapt.
    Thanks for your help! Gil

  8. Hi to all,. . Need tool for checking content copyright.

Leave a Reply to gilnycCancel reply

Trackbacks and Pingbacks: