Python on Windows. Kthxbye!

Download PDF

[Cross-posted from ICanHazDataScience]

At one point, I had Windows, Mac and Linux laptops, an android tablet, android phone and iphone… but now I’m just down to the things that aren’t forbidden fruit.  I used to write all my code on the Linux machine, and use the Windows one for writing (it has a bigger screen that lets me view two documents side-by-side).  But now I *like* coding on my Windows 7 machine. Here are some of the things that I’ve learnt doing it.

  • Find some friendly instructions to help you with things like setting environment variables (i.e. the thing that means you can just type “python” in your terminal window instead of a really long address to the python executable file).
  • Install 32-bit Python instead of 64-bit Python.  Yes, it sounds wierd on a 64-bit machine, but trust me, some libraries will break horribly (and some will be just plain unavailable) if you try using the 64-bit version.  The 32-bit version works fine, honest!
  • “Real” coders will laugh at you in Hackathons.  Ignore them… or just blow them away with your awesome webpage scrapers.
  • Python 3.x is the latest version, but Python 2.x has better support. I’m currently on Python 2.7.3.  It works.
  • If you’re adding Python libraries (aka “packages”) to your machine (and you will), pip wins out over easy_install because it comes with things like uninstall (easy_install doesn’t).  Install Distribute, then install Pip… here are some geek notes on why and how.
  • Some packages need slightly different code if you’re running on a Windows machine.  for instance, connecting to Skype using Skype4Py has these variations between machines:
import os

import Skype4Py

 

if os.name == “nt”:

print(“Windows”)

#32 bit and 64 bit windows behave differently with Skype

if ‘PROGRAMFILES(X85)’ in os.environ:

sconn = Skype4Py.Skype() #64-bit

else:

sconn = Skype4Py.Skype() #32-bit

elif os.name == “os2”:

print(“Mac”)

sconn = Skype4Py.Skype()

else:

print(“Linux machine or similar”)

sconn = Skype4Py.Skype(Transport=’x11′)

(That was a very hard-won piece of code. It won’t happen to you often, but occasionally you need to ask whether it’s your machine type that’s the problem).

  •  Virtual environments rock. Mostly.  But in windows, you have to connect them to your Postgresql databases the hard way.  VirtualEnv is the package that you use to create virtual environments on your machine, that you can use to mimic the environment that you’ll eventually distribute your code in online (e.g. Heroku or Amazon).  You don’t need it yet, but it saves a lot of time when your code’s ready to show the whole world.

 Well, that’s just a few things I’ve learnt.  I know I should be a hard-core coder who defends Linux to the hilt – and I like Linux a lot (heck, I can remember when Vi was young and Emacs was a hot new thing), but I’m also very aware that a lot of the people who are managing, analysing and creating data are using Windows machines to do it, and I don’t want to be another person getting in the way of them starting to code on said machines.

Onwards!