views:

10945

answers:

8

I am finding it difficult to use MySQL with Python in my windows system.

I am currently using Python 2.6. I have tried to compile MySQL-python-1.2.3b1 (which is supposed to work for Python 2.6 ?) source code using the provided setup scripts. The setup script runs and it doesn't report any error but it doesn't generate _mysql module.

I have also tried setting up MySQL for Python 2.5 with out success. The problem with using 2.5 is that Python 2.5 is compiled with visual studio 2003 (I installed it using the provided binaries). I have visual studio 2005 on my windows system. Hence setuptools fails to generate _mysql module.

Any help ?

A: 

You're not the only person having problems with Python 2.6 and MySQL (http://blog.contriving.net/2009/03/04/using-python-26-mysql-on-windows-is-nearly-impossible/). Here's an explanation how it should run under Python 2.5 http://i.justrealized.com/2008/04/08/how-to-install-python-and-django-in-windows-vista/ Good luck

Mork0075
+1  A: 

There are Windows binaries for MySQL-Python (2.4 & 2.5) available on Sourceforge. Have you tried those?

Dave Webb
Installing using the binaries worked. Thanks!
Sammy
The 2.5 (and 2.4) binaries fail to install if only 2.6 is installed
David Sykes
That will be because the versions have to match. There's a link to MySQL-Python 2.6 for Windows in this blog post but I haven't tried it: http://timvalenta.wordpress.com/2009/02/04/python-26-mysql/
Dave Webb
+6  A: 

Hi, I found a location were one person had successfully built mysql for python2.6, sharing the link, http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe

...you might see a warning while import MySQLdb which is fine and that won’t hurt anything,

C:\Python26\lib\site-packages\MySQLdb__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet

After an 8 hour battle I finally came across this. Thank you thank you thank you!
David Sykes
Worked perfectly for me, thanks.
jfar
A: 

You might want to also consider making use of Cygwin, it has mysql python libraries in the repository.

lfaraone
+3  A: 

As Python newbie learning the Python ecosystem I've just completed this.

  1. Install setuptools instructions

  2. Install MySQL 5.1. Download the 97.6MB MSI from here You can't use the essentials version because it doesnt contain the C libraries.
    Be sure to select a custom install, and mark the development tools / libraries for installation as that is not done by default. This is needed to get the C header files.
    You can verify you have done this correctly by looking in your install directory for a folder named "include". E.G C:\Program Files\MySQL\MySQL Server 5.1\include. It should have a whole bunch of .h files.

  3. Install Microsoft Visual Studio C++ Express 2008 from here This is needed to get a C compiler.

  4. Open up a command line as administrator (right click on the Cmd shortcut and then "run as administrator". Be sure to open a fresh window after you have installed those things or your path won't be updated and the install will still fail.

  5. From the command prompt:

    easy_install -b C:\temp\sometempdir mysql-python

    That will fail - which is OK.

    Now open site.cfg in your temp directory C:\temp\sometempdir and edit the "registry_key" setting to:

    registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1

    now CD into your temp dir and:

    python setup.py clean

    python setup.py install

    You should be ready to rock!

  6. Here is a super simple script to start off learning the Python DB API for you - if you need it.

+26  A: 

This page has python-mysqldb binaries for:

And also for embedded MySQL.

This discussion has some tips about getting rid of the deprecation warning.

itsadok
Can anyone confirm that the first linked executable works with Python 2.6? The installation splash screen says it's only 2.5 - but I'm presuming the person who built it may just have not updated that line of documentation.
John C
A: 

http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe

Blog of Jan. 4: "On the danger of Islamist terror"

I think I'll pass.

RJ
+3  A: 

This may read like your grandpa givin advice, but all answers here did not mention the best way: go nd install activestate python instead of python.org windows binaries. I was really wondering for a long time why python development on windows was such a pita - until I installed activestate python. Ia ma not affiliated with them. It is just the plain truth. Write it on every wall: python development on windows = activestate! you then just pypm install mysql-python and everything works smoothly. no compile orgy. no strange errors. no terror. just start coding anddoing real work after five minutes. this is the only way to go on windows. really.

Gorgonzola Balistico Refurbo B
It would be a perfect solution if a Business Edition subscription wasn't necessary...
matheus.emm
@matheus.emm - Business Edition is not necessary for installing MySQLdb on Windows 32-bit.
Sridhar Ratnakumar
@Sridhar What do you mean? When I tried to execute the command to install mysql-python a message was displayed saying that a Business Edition subscription was necessary. Is the a (legal) way to install mysql-python without this subscription on Windows 7 64 bits?
matheus.emm
@matheus.emm - For free access, you can install ActivePython **32-bit** on your Windows 7 64-bit OS and then install mysql-python. ActivePython 64-bit does require a BE subscription for installing packages.
Sridhar Ratnakumar