Let me tell you first how I got into writing my 1st python program. I wanted to have a look at the database schema of OSQA (Open Source Question Answer) and there was no database model available online. So my only other choice was to download the source code and setup the application. Now OSQA runs on Django, python and MySql. I already have a running instance on MySql on Windows 7. So I had to download python and installed it on Windows. I got an MSI installer from the official python website and it installed with no problems. OSQA requires you to run manage.py syncdb -all to create the database it requires. I tried that command in IDLE but it complained about Django. So I went to download Django framework and got it installed as well. Since OSQA source files was in a different directory from where python was installed, I was having a hard time trying to get the command to work. Therefore I tested a line command from the IDLE command prompt (print hello world). This worked which means the python interpreter is OK. I then saved this code in a file called hello.py and saved that file in the OSQA folder. Surely this must work now but it didn’t. You have to add python to the Environment variables on Windows to ensure it works correctly. I also added the Scripts folder to environment variables (C:\Python27\Scripts). Once that is done, hello.py worked fine. So this was my first Hello World python program.
Now my problem was still not solved. The manage.py program would still not run and when I checked the errors, I saw that it was looking for MySql library. MySql for Python was required and a few other libraries as well to make OSQA work. I was only going to add the libraries which are required to get the database schema, so I downloaded MySql for Python and tried to install it on Windows 7. Big problem! The list of problems are as follows:
- If you don’t have development bits for MySql, it won’t work. So modify your current instance of MySql and check that development bits are selected. After successful install, you will have an include folder in your current MySql installation path with .h files.
- Second problem is that on Windows 7, the registry for MySql is located at SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.1 instead of SOFTWARE\MySQL AB\MySQL Server 5.1 because Windows 7 is 64 bits rather than 32. So make sure the site.cfg file of MySQL-python-1.2.3 has the above registry and change MySQL Server 5.0 to 5.1 if you’re running MySQL 5.1
- Third problem is that you need to modify your C:/Python27/Lib/distutils/msvc9compiler.py and add ld_args.append(‘/MANIFEST’) after ld_args.append(‘/MANIFESTFILE:’ + temp_manifest). Make sure you edit this file in IDLE (the python scripter) otherwise you’ll get errors because of white space. It will complain about indentation. I tried editing this in Notepad++ and although it looked fine there, when I open the file in IDLE, there was spacing problems.
- Fourth problem is that MySQL-python-1.2.3 requires Visual Studio 2008 and since I’m running Visual Studio 2010, it’s not getting the right libraries to install MySQL for Python.
I’ve left it as that for the time being because it’s just too much work for something that’s not really necessary!
UPDATE : I managed to install MySQL-Python-1.2.3 through an installer instead (http://www.codegood.com/archives/129)
UPDATE 2 : On top on MySql for Python, I had to install Markdown and Html5lib as well to get the OSQA database created.