I’ve been wanting to try my hand at SQLAlchemy for a while now. No particular reason other than checking how the APIs for the ORM are. To decide on the database to use, I thought MySQL might be a good idea because most of the OSS libraries support MySQL. But the catch was that I wanted to do all this on Windows 7 and that too a 64-bit Windows 7. So, this was a bit tricky. I couldn’t do something like easy_install MySQL-Python on Windows. So, here is a step-by step guide to install MySQL 64-bit, Python-MySQL on Windows 7. The steps might work with Windows Vista too.
Pre-requisites
- Python 2.7 – might not work with Python 3
- Visual Studio 2008. The Visual Studio express edition will also work. Essentially, a C++ compiler is required
- Access to modify the registry
- MySQL DB 5.5 on Windows
Installing Python-MySQL
- Download the combined installer of the MySQLDB on Windows from MySQL. The current version is 5.5
- Download the Python-MySQLDB library here – Python-MySQLDB. The current version is – MySQL-python-1.2.3
- You need to have the Microsoft Visual Studio installed on your machine. I had Visual Studio 2008 installed, but this can work with the Microsoft Visual Studio Express edition too
- Install the MySQLDB – select the ‘developer’ configuration during install. This will install the required libraries and the header files for the C connector- these are important. Note the directory that you are installing the MySQL
- This will install MySQL 64-bit on the machine. I am running Windows 7 64-bit and hence I installed the 64-bit version of MySQL
- Extract the MySQL-python-1.2.3 into a directory
- Open the site.cfg and make the following modification
-registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0
+registry_key = SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.5
Based on the version of the MySQL server, change the 5.5 to whatever is the version you installed. On Windows 7 (and I think on Vista too) 64-bit, the registry key is changed to this location during installation. This took me a long time to find. This has been documented here too – MySQL-Python forum (check for the comment no. 13) - Then modify the setup_windows.py by adding the lib_dirs and include_dirs. Here we add the directories for the C connector that was installed as part of the installation of MySQL. I could not locate the registry key for the connector, so I added the directories for the headers and the libraries to the compiler parameters. Note that I added the opt-imized library directory. If you are debugging the MySQL connector, you will want to include the debug version of the libraries
library_dirs = [ os.path.join(mysql_root, r'lib\opt'), "C:\Program Files\MySQL\Connector C 6.0.2\lib\opt" ]
include_dirs = [ os.path.join(mysql_root, r'include'), "C:\Program Files\MySQL\Connector C 6.0.2\include" ] - One final step and you are ready to go. As documented – here, you need to modify the msvc9compiler.py. Look for the line containing
ld_args.append('/MANIFESTFILE:' + temp_manifest)and add a new line –ld_args.append('/MANIFEST') - Now install the python library using – python setup.py install in the MySQL-python-1.2.3
- This will use the Visual Studio compiler and the file mentioned in the include_dirs, library_dirs to build the .egg file for the MySQL-Python libraries
- Some more help here
- Also can check this on SO though for the 64-bit windows, I found that this solution did not work
Pingback: Compiling MySQLdb 1.2.3 on Windows 32 and 64 – Without need the MySQL Database 5.5 installed « Victor Jabur's Blog