Writing my first Python program on Windows 7

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:

  1. 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.
  2. 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
  3. 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.
  4. 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.

Holiday to Cyprus

Just came back from a holiday to Cyprus on a self catering basis. We went to Ayia Napa to enjoy the beautiful Nissi beach. The flight time from UK (Luton Airport) to Cyprus is around 5 hours and we travelled by Monarch Airlines. We landed at Larnaka airport where a private taxi was waiting to take us to Elena Court in Ayia Napa. The transfer time was around 40 mins and the drive spoke little english so it was hard to make an actual conversation with him.

Once at the apartment, we met Jon who works for Overseas Keys. He showed us the apartment and made me signed some documents just in case we break things. No sooner than Jon was gone that we headed for the shops to buy the basic things that we needed – milk, bread, butter etc. The shops/supermarkets were only 5 mins from the apartment but we walked along the main street to get a better idea of what was around us.

Although there was a swimming pool in Elena Court, we did not use it because we did not see the point since Nissi beach was extremely beautiful. The water is crystal clear and increases in depth gradually which makes it very likeable. We spent most of our time at Nissi beach although we did enjoy the waters of Macronissos beach as well. Other beaches were not as nice as those 2, for example, Lande beach was a bit too wavy as well as the other beaches on the opposite side of Nissi.

We went to the Harbour one time and it was such a struggle to walk in the heat that Cyprus provided in the month of October. Instead of taking a taxi to come back, we decided to take public transport and the bus cost us a euro each and the air con was nice. It was the first time we travelled by bus in a foreign country.

There are lots of souvenir to take from Cyprus and the things which caught my attention were the shells.  You can have really big shells with different designs for around 20-30 euros or a pack of small shells for 5 euros.

All in all, we had a really great time in Cyprus and it is well worth the money spent.

The breakpoint will not currently be hit – Visual Studio Debugging

Debugging your application is a great way to find the cause of a problem. However you may sometime encounter the dreaded “The breakpoint will not currently be hit. No symbols have been loaded for this document.” error. You can find fixes to this problem by following this link.

If like me, none of the above methods work for you, then there could be something else that’s preventing the debugger from working. So I tried creating a new application (web) using Visual Studio 2010 and set a breakpoint to see if it works. As soon as I start debugging from VS2010, the ASP.NET Web Development server kicks in and tries to open the webpage and then switches back to visual studio on my breakpoint. This means that debugging should work fine. I tried it on Firefox and Internet Explorer but it doesn’t work though. By that time, I’ve come to the conclusion that the debugger is not attaching itself correctly to the web server which is hosting my application. Note that the default web server that comes with visual studio opens the webpage either in Firefox or Internet Explorer but uses something like localhost:45609 to accomplish that.

My web app was hosted on IIS7.5 under Windows 7 and I had to attach the debugger to w3wp.exe worker process responsible for asp.net requests. Once this is done, the breakpoints work like a charm.

Should we ditch .net for open source?

I’m a .net guy and love programming in c#. It’s rare for me to look at other programming languages because I tend to stick to aso.net because I can easily get a project off the grounds as I know pretty much the inside outs of the syntax etc. I can code in php as well but I never really liked it as I get more control in .net. From a developer’s point of view, coding in the latest technology is the best way to stay motivated and learn the new stuff. That’s what we want cutting edge technology! However from a business perspective, it’s a different story. For the business, profit is what dictates its strategy. If there are no real benefit to using a certain technology, then most likely it’s not going to be adopted.

For a small company, microsoft products can be quite expensive. For easy programming in .net, you really need to have Visual Studio. Of course you need IIS as your web server and many .net programmers will want Microsoft SQL Server as well. This is all good but the costs of these things can amount to a lot. So you small business owners ditch .net for open source technologies? Well that really depends on the situation. Apache is a good webserver and is free as well as MySql. The standard approach is to use PHP to develop the website and host it on a linux box which is considerably cheaper than having to pay the licence for Windows Server (2008) and getting Microsoft SQL Server 2005/2008. With the Windows Server, you get IIS as your web server to run your website but you still need a database. MS SQL Server is very expensive, it costs pretty much the same as a dedicated server.

When I was looking at a dedicated Windows Server, you have to pay £99 per month for the server, £25 a month for Windows 2008 Standard Edition (the licence fees) and £99 for Microsoft SQL Server 2005/2008 Standard Edition (the licence fees). Now these are significant costs as you end up paying £223 per month for a .net site compared to £99 a month for a site done in PHP running on Apache with a MySql database.

When I thought about the costs involved, I wantet to switch to open source technologies so that I don’t end up paying so much money for my websites. I was looking into Django as it claims to make website designing quicker and better but after my extensive research, I came to the conclusion that it was not really worth it. As I explained in the post on DJango, there are a lot of things to consider before making such a decision. For example, putting aside the differences in programming syntax for Django (python) vs asp.net, I conclude that it’s going to take me more time to deploy a website using Django because of various configuration needed at the server level. I think that an IDE is really important when programming. Take Visual Studio for instance, you have intellisense which makes it quicker for you to code. You can go to a method’s definition to see what’s happening there and have debugging facility as well. You can write unit tests to see whether things are working as expected. You get to compile your website and see errors beforehand. I’m probably biased but I think I’ve got more control with .net than the open source languages.

There are a lot of advantages when programming in asp.net and it is a true object oriented programming language (C#). However I still find that Microsoft SQL Server is very expensive. I wouldn’t change C# as my main coding language but I’ll definitely look into an open source database like MySql or postgresql. The reasoning behind this is very simple; I do not need the special capabilities of MS SQL Server at the moment, I simply need it as a storage engine. I use nHibernate for the database abstraction and that makes it even easier to switch to another data store. At the end of the day, you have to pay to get a good product with all the facilities that you want. Just like you pay for MySql if you want their extended support, you need to pay Microsoft for using their technology!

Django – can we build low cost and scalable websites?

Django seems to be the new craze these days like Ruby on Rails was some time ago. The adoption of Django seems to be rising each month while Ruby seems to be quiet. So what exactly is Django about?

Django was developed by a group of developers with a budget restriction. So they made use of things that were free – chose Apache as the webserver, mysql as the database and python as the programming language. That’s all good and it gets even better because Django is sort of like Model View Controller (MVC). Why sort of? It’s just because the view is not really a view; you need to have a template (the real view) associated with it. From the looks of it, it’s quite easy to program in django, however when you’re used to certain programming language like C#, it might not be so obvious.

The problem with Django is that you really need to know Apache or Linux. At the moment, it is not widely supported. So if you have built your website in Django and want to publish it, you might run into problems because chances are that your hosting company doesn’t know how to get Django to work and if it’s shared hosting, they probably won’t give you access to modify the server properties. If like me, you’re not really into that apache stuff, then it will be more of a problem because apache needs to be configured a certain way. On top of that, django does not serve media files from what I understand, so your images, videos, audios and style sheets will have to be passed on to apache through another configuration. I personally find it hard to believe that the guys who developed django said it was meant to make web site development faster and cheaper.

When programming in django, you will have to use the command line utility extensively to create projects, compile etc. It’s like going back to the DOS era. There’s no IDE specific to django at the moment although you could get plugins to highlight the syntax. It’s like programming in notepad with no intellisense.

Personally I don’t think Django is the right choice for me. It can be for other people but the disadvantages far outweigh the advantages for me.