Install Python-MySql on Windows 7 64-bit

Install Python-MySQL on Windows 7 64-bit

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

  1. Python 2.7 – might not work with Python 3
  2. Visual Studio 2008. The Visual Studio express edition will also work. Essentially, a C++ compiler is required
  3. Access to modify the registry
  4. MySQL DB 5.5 on Windows

Installing Python-MySQL

  1. Download the combined installer of the MySQLDB on Windows from MySQL. The current version is 5.5
  2. Download the Python-MySQLDB library here – Python-MySQLDB. The current version is – MySQL-python-1.2.3
  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
  4. 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
  5. 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
  6. Extract the MySQL-python-1.2.3 into a directory
  7. 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)
  8. 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" ]
  9. 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')
  10. Now install the python library using – python setup.py install in the MySQL-python-1.2.3
  11. 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
  12. Some more help here
  13. Also can check this on SO though for the 64-bit windows, I found that this solution did not work

Setup Samba on Ubuntu Jaunty

samba connect failed NT_STATUS_BAD_NETWORK_NAME ubuntu, samba connect failed ‘Access Denied’, Samba connect failed ‘Invalid password’

So, I have a VM on which I installed Ubuntu Jaunty. I was using it sparsely, but realised that some projects are better off being built on Linux than on Windows Vista that I run (don’t ask, the machine came preloaded with Vista !).

Installing Ubuntu was not a problem. Using xming to get the X was also not a big problem. Well, it was a problem initially; and then had to fix the (rather unintuitive UI) firewall settings to allow connections between the guest and the host.

The problem though was getting Samba to work. Now before you ask me to RTFM, let me answer that one needn’t read the whole manual. Just follow these instructions on installing Samba on Ubuntu and to access directories on Linux from Windows. Very simple eh; well so I thought. I did everything that was documented, but still no love. I was trying to share the home directory of the Linux user on Windows. The user names on Linux and Windows were same. I setup the workgroup to be the same too (in the /etc/samba/smb.conf). Even then, I could not connect to the Linux machine.

One of the nice links to troubleshoot this problem of connectivity, especially the NT_STATUS_BAD_NETWORK_NAME was this one. I found out a few commands to check the samba configuration. Even then no luck.

So, I go back to original link and try to find out what I am doing wrong. And then in the comment section I see this gem of a comment by user Kim SJ.

Took me a while to notice that the “[homes]” line is commented out as well as the lines in that section. Maybe others will fall into that trap too… hope this helps.

And that is when it hit me ! The [homes] section in the /etc/samba/smb.conf on my VM was commented. After I modified the file and I can connect to the Linux share. What a thing to miss ! So, to setup samba on Ubuntu jaunty, where you want to share the user’s home directory, you need to do this

sudo apt-get install samba smbfs
sudo smbpasswd -a <Linux_username>
sudo vi /etc/samba/smbusers
#add this line
<Linux_username>= “<Linux_username>”
sudo vi /etc/samba/smb.conf
# add two lines after Authentication
security = user
username map = /etc/samba/smbusers

# Uncomment below three lines – including #the [homes]
[homes]
comment = Home Directories
browseable = yes
# add line
writable = yes

The <Linux_username> is the Linux user whose home directory you wish to share. For my Linux machine running on a VM, this is good enough. I keep the usernames same between my Linux machine and the Windows machine and things work fine. I noticed that if the passwords are also the same, then I needn’t provide the password when I map a network drive using net use. Awesome !

New age content production

Ok, so the title is not to make it sound like a oft repeated, boring phrase about the Internet era. Rather, it is an indication of the (rather quiet) change in the way content production, validation and consumption has been changing in the last 5 years. And given that that is not a very long period (I can say that I am part of those times !). Ok, so what am I talking about. I am trying to summarize the views of Yochai Benkler on Open Source Economics. Before you start contorting images of nerdy software developers writing code after they come back from work (generally due to lack of much social interaction), and un-social beings with long beards trying to fight monopolistic software companies, go check out the talk (and yes, part of your imagination might be (unfortunately )true).

Mr. Benkler tries to summarize (very concisely), the power of the open source community. And this open source community is everyone who has an Internet connection and is willing to do something that interests them. As he says in the talk, money is not always the motivation. Yes, indeed. Even though money is good to have, it is not always the only motivation. Case in point being, wikpedia – and that is what he talks about. To be able to harness the power of humans as social beings is a powerful concept which has started to grow in the last decade. Like he says in the video, we have always tried to help each other out, but now the reach of this has grown from merely a cup of sugar / achar / curd, but stuff that can make a difference in our lives. Self-censuring as manifested in wikipedia or collaboration as in CPU power for SETI@home is not a fad, but is something that will get even more prolific in the near future.

The summary of the talk, is what I thought the best part of it. Social production will continue for long, but, it is threatened by the incumbent industrial systems. An intellectual property decision / telecom decision is not a technical decision, but a decision that will effect the future of our being as social beings and the way information, knowledge and culture will be produced. It is about how the industrial way of content production competes with the new age content production.

Nessus on Windows using Cygwin

This is one of the most often asked questions on the Nessus mailing list. And the reason is quite obvious. In general people have an easy access to a Windows box than a *nix (for whatever reason). And the next to working on *nix would be to use their favourite programs on Cygwin. I myself am a big user of Cygwin.
One of the primary reasons that running Nessusd on a Windows box is the Cygwin-Windows-fork() performance problem. As stated on the Nessus-Devel list and elsewhere this drop in the performance is because of the way fork() is implemented in *nixes and Windows. I would write about the fork() on linux later. Let me describe what you need to do to get Nessus running on Windows.
Continue reading “Nessus on Windows using Cygwin”

Desktop managers, Window Managers, XServer

One of the first questions that pops up for a beginner to GUI development on Linux is the different terms – there is XServer, there is the desktop manager, there is the window manager. And if you are a beginner then it might take you sometime to understand the relationship between these three. In simple terms, the three are layered thus (in the order of interaction with the hardware)

  • Desktop Managers
  • Window Managers
  • XServer

Continue reading “Desktop managers, Window Managers, XServer”

Java and the Open Source happenings

Let me start with the disclaimer. I am not a Java developer. I can only System.Out.Println in Java. Off late there have been a lot of discussions about open sourcing Java. ESR requested Sun to open source Java, to make it a viable alternative to Microsoft’s offerings. In the era of WebServices J2EE becomes one of the mature enterprise class framework. And to further it on Linux seems to be the next natural thing.
This letter generated a lot of discussions and the response from Sun made ESR clarify on what he exactly meant by open sourcing Java. From a open-source minded person this seems to be a very valid request and clarfication. A bigger explaination on why this has to happen highlights other points.
Continue reading “Java and the Open Source happenings”

The first open-source contribution

There it was, after almost 10 months of sporadic changes in code and a month after I managed to get it in shape, I made the first open source contribution yesterday. I managed to goof up a little with CVS, but in the end realised that the damage done was nothing. But even otherwise I must admit quite candidly that my working of knowledge of version management systems is rather primitive. Even though I am a full time s/w developer this is something I do part-time <grin>.
I am not providing the link to the site, coz I want to get the source in proper shape and then I will update this post with the link. Till that time, let this post herald my entry to the open source world. And may be soon, I will put up the emblem on my homepage. Keep watching this space till then…